16-06-2021, 04:54 PM
(This post was last modified: 16-06-2021, 05:02 PM by josemendez.)
(16-06-2021, 03:33 PM)Hakazaba Wrote: Aparently the order of operations is a little bit more complicated according to this thread, in regards to OnEnable: [url=https://forum.unity.com/threads/onenable-before-awake.361429/]https://forum.unity.com/threads/onenable-before-awake.361429/
That thread describes the usual, documented behavior:
- For each object, Awake() is always called before the same object's OnEnable().
- For different objects, there's no guaranteed relative ordering of their events unless you specify otherwise in the Script Execution Order window.
That means if you have 2 objects with no hand-specified execution order, you can get several call orders:
#1) object1.Awake()
#2) object1.OnEnable()
#3) object2.Awake()
#4) object2.OnEnable()
#1) object1.Awake()
#3) object2.Awake()
#2) object1.OnEnable()
#4) object2.OnEnable()
#1) object2.Awake()
#2) object2.OnEnable()
#3) object1.Awake()
#4) object1.OnEnable()
...etc.
What you will never get is an object's OnEnable called before its Awake() function. So, this cannot ever happen:
#1) object2.OnEnable()
#2) object2.Awake()
See:
https://docs.unity3d.com/Manual/ExecutionOrder.html
Specifically, the "Update Order" section.