- Home /
Awake/Start order across different platforms.
I'm aware that I can't rely Awake ()
to be called in hierarchical or some other predictable order between builds and changes in a scene. However, I can observe that awakes will be invoked in the same exact order when neither code nor data were changed between runs. And this is a very important feature, especially when you write lock-step synchronization between clients. It makes you certain that every bit of synchronization-sensitive data gets initialized on all clients in the same exact way in every aspect. This leads to the following question: if I publish and deploy same exact code with the same exact data to some other platform, will this order remain intact? Is there any chance that developers of unity engine internals have some specification on this topic that they adhere to, upon writing runtimes for each platform?
Answer by Eric5h5 · Dec 24, 2015 at 01:35 AM
There is no guaranteed order for anything except as explicitly documented. So no, you can't expect GameObjects to run Awake functions in any particular order unless you do something to make that happen. Relying on undocumented behavior is pretty much 100% guaranteed to backfire...even if something works consistently now, it can and will change in the future.
Thank you. This knowledge saved a lot of my time and gave me certainty about which way I must go in further development.
Answer by maccabbe · Dec 23, 2015 at 09:35 PM
Probably there is a misleading information in my original post. $$anonymous$$y question was not about "what precedence of the Awake/Start/Update calls", but "do GO1, GO2 and etc. receive Awake () in the same order after deploying to a different platform? Same question about Start () and Update ()." Sorry for that. I guess, I have to add more details to my post.
Answer by GiyomuGames · Dec 24, 2015 at 07:24 AM
A bit late but you can also specify the order of your scripts, which will force awake etc. to be called in a certain order: http://docs.unity3d.com/Manual/class-ScriptExecution.html
Thank you for your effort, but question was slightly different :) Consider scene with the following hierarchy:
GameObject1
Behaviour1
Behaviour2
GameObject2
Behaviour1
Behaviour2
Each behavior implements Awake ()
and writes into log string of the form "Awake():GameObject1:Behaviour1". After hitting play you can get following output:
Awake() :GameObject1:Behaviour1
Awake() :GameObject1:Behaviour2
Awake() :GameObject2:Behaviour1
Awake() :GameObject2:Behaviour2
Or you can get this:
Awake() :GameObject1:Behaviour1
Awake() :GameObject1:Behaviour2
Awake() :GameObject2:Behaviour2
Awake() :GameObject2:Behaviour1
In general, you can get almost any combination in output. However, it's only shuffled after you rebuild your project or change scene data. On the contrary: in subsequent runs with no modifications in code and data you get same output on each run. The question is: does order preserved in builds targeted to different platforms and can this behavior be relied upon?
Your answer
![](https://koobas.hobune.stream/wayback/20220612053618im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Execution Order of Scripts - Awake and OnEnable 1 Answer
Cached references set in awake aren't persisting 0 Answers
Awake called after I activate object, not after Instantiate... is it normal?? 2 Answers
DontDestroyOnLoad() not calling awake/start again 2 Answers
Object reference becomes null between Awake and Start after scene load 2 Answers