Find object by tag after LoadLevel

So,this is my script :

GameObject mainController = GameObject.FindGameObjectWithTag("MainController");

I want to find gameobject from loaded scene, as i understand, i’m doing it wrong(mainController is null). How can i find gameObject after I loaded scene ?

You could use OnLevelWasLoaded()

If your finding script is located in the scene itself, you can user Start or Awake.

As soon as the Application.LoadScene(“Scene”); is executed,Unity will load the new scene and destroys all the objects in the current scene. You could instead get the object by using the same line GameObject mainController = GameObject.FindGameObjectWithTag(“MainController”); inside the Awake() function of the loaded scene.