- Home /
Find object by tag after LoadLevel
So,this is my script :
Application.LoadLevel("scene");
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 ?
Answer by YoungDeveloper · Nov 30, 2014 at 12:35 PM
You could use OnLevelWasLoaded() http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html
If your finding script is located in the scene itself, you can user Start or Awake.
Answer by Vicky Pinakin · Nov 30, 2014 at 01:02 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613172808im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to keep the script working after scene load? 1 Answer
LoadSceneMode.Single seems to be not working. 0 Answers
Why does a scene loaded from an Asset Bundle returns empty string when getting its name? 0 Answers
Is there a callback for when a scene gets unloaded in the Editor? 1 Answer
My Scene won't load in, and is stuck in "WaitForPlayEnter" 0 Answers