Start/Awake not being called on DontDestroyOnLoad GameObjects

Updated on April 7, 2016 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on April 7, 2016

I have a player which is set to DontDestroyOnLoad . Among it , it have code which calculates some data according to new loaded scene . I want to do this calculation when the scene is loaded . Since i am setting the player not destroy on load , the start function is not being called . Is this suppose to be bug or if any solution for calling this code after the scene is loaded .

If anyone wanna know how , heres answer i just posted in<a href="http://answers.unity3d.com/questions/1160006/how-to-add-a-delegate-to-this-to-get-notifications.html#answer-1167561″> unity answers 🙂 

  • Liked by
Reply
4 on April 7, 2016

Well, Start will only get called when the object is instantiated. So it’s not a bug.
Use this instead: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html

Devoted
on April 7, 2016

Yea , sorry i forgot to mention about OnLevelWasLoaded , its not working anymore in unity 5.4 beta version . ( Its Obsolete )

Guru
on April 7, 2016

Oh yeah! I see.
So apparently it’s been replaced with the SceneManager.sceneLoaded delegate.
With that you can call your own method.
You know how delegates work?

Devoted
on April 7, 2016

owh , thx for showing that , i missed that . And yea i know delegates 🙂

Guru
on April 7, 2016

Nice! 🙂

Show more replies
  • Liked by
Reply
Cancel