- Home /
GameObjects Created Twice from Application.LoadLevel?
I just noticed something odd: OnDestroy is called on all scripts attached to objects in the hierarchy when your scene is loaded from another scene, before Start(). The objects don't exist in the previous scene that loaded them and there is nothing marked with DontDestroyOnLoad.
To test, I'm calling Debug.Log in the Awake, Start, OnDestroy and OnApplicationQuit of different C# scripts. The result for all cases is:
When loading the scene directly in Unity and hitting "Play", everything starts normal (Awake() and then Start() are each called once as expected).
When coming from another scene that calls Application.LoadLevel on this scene from its OnGUI (and which again does not contain any instances of these), Awake is called, then OnDestroy, then Awake again, then Start.
So it seems all objects in the hierarchy of a scene loaded with Application.LoadLevel are being created, then destroyed before Start is called, then created a second time. There is nothing in any of the Awake methods (or anywhere else in the game for that matter) that destroys any of these objects implicitly.
Does this seem normal?
Your answer
Follow this Question
Related Questions
Cached references set in awake aren't persisting 0 Answers
when loading a scene, the execution order is load->constructor->finishfunction->awake->start? 1 Answer
FindGameObjectWithTag wont find in Start() or Awake() but will in Update() 1 Answer
ExecuteInEditMode Component construct "twice" and "reset" custom classes 0 Answers
OnEnable, Awake, Start order 8 Answers