[Solved] No overload for method Quit' takes 1 argument

I read online that I might be compiling on a different version of that class? and that the error is not in my code itself? Also that I should try a “Clean Build” which I do not know what that means



I have never seen this error before & really just don’t know whats going on with it.
Any help is appreciated thank you.

Hi,
Did you upgrade to unity 5 ?
It seems you have to use scenemanager to call your scene:
using unityengine.scenemanagement

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

2 Likes

Hi Logan,

The error regarding Application.Quit() is because it doesn’t take a parameter like the, now obsolete, Application.Load() method did. All it does (assuming the correct build platform) is quits the application. It won’t take you to a “quit scene” as such.

You can resolve this by changing your code from;

public void QuitRequest(string name) {
    Debug.Log("I want to quite" +name);
    Application.Quit(name);
}

to;

public void QuitRequest()
{
    Debug.Log("I want to quit");
    Application.Quit();
}

If I had to guess I would say that you may have copied the LoadLevel() method and as such the name parameter went across with it and you just renamed the LoadLevel() method to Quit(), so that’s a nice easy fix.

Regarding the LoadLevel() method being obsolete, obviously @Dieedi has already provided you with some information. Basically as of Unity 5.x Application.LoadLevel() became obsolete and was replaced with SceneManager.LoadScene().

This new class and method has the same signatures, e.g. LoadScene(string name) and LoadScene(int sceneIndex) however you must use an additional directive at the top of your class;

using UnityEngine.SceneManagement;

So, for a complete fix;

using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour
{
    public void LoadLevel(string name)
    {
        Debug.Log("Level load requested for " + name);
        SceneManager.LoadScene(name);
    }

    public void QuitRequest()
    {
        Debug.Log("I want to quit");
        Application.Quit();
    }
}

This scenario is actually one of the reasons why you may create classes such as this LevelManager, it enables you to have your application point to your methods for loading scenes, but if something in the underlying code changes, you only need to then change it in one place.

For example, without the LevelManager every one of your scenes would need a script to handle loading the next scene based on a win/lose condition. Then along comes Unity and some methods are now obsolete, you would now need to go through every one of those scripts and change them individually. By using the LevelManager in this way, you can make the change once and you do not need to make all of those individual changes - kinda neat :slight_smile:

By the way, with code queries, it’s often easier if you paste the code into your posts rather than the screenshots, maybe save those for queries relating to the editor or images of scenes and so on. The forum will support you pasting your code directly into your posts and this makes it quite easy for us to respond and help as we can copy and paste chunks of your code. :slight_smile:

I hope the above is of use.

ps. The Clean Build option in both MonoDevelop and Visual Studio clears build objects from previous builds, you may find these in /debug or /bin directories within the project. This is useful sometimes when you want to be sure that nothing is being cached, although I can honestly say I’ve not needed to use it with any of my Unity projects to date.


See also;

1 Like

Privacy & Terms