Unity Script can not reach Game Manager after loading a new scene

Viewed 396

If i load a new scene in my project, i get "Object Reference not set to an instance of an object" error about my Game Manager. For example, this error occures in another script reaching "GameManager.instance.LevelStarted" and another variables from GameManager.instance.

But i set up my Game Manager with instance like this in my GameManager.cs script:

public static GameManager instance;

    void MakeSingleton()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    void Awake()
    {
         MakeSingleton();
    }

I load a new scene in my Game Manager like this:

    public void Restart()
    {
        SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
    }

What am i doing wrong? What should i do my scripts to reach GameManager variables after loading new scene?

0 Answers
Related