The previous article tested the effect of the build order on the order of execution, linking: Link
This article mainly tests the loop order of the three common messages in Awake,onenable,start
First one of the simplest print test code
void Awake () { Debug.Log ("awake" + name); } void onenable () { Debug.Log ("onenable" + name); } void Start () { Debug.Log ("Start" + name); }
Print Message
The test results are awake and onenable in the first cycle, start in the second cycle
Then test the order of dynamic creation
Public TMP template; void Start () { var go = instantiate (template.gameobject); Print ("--creater modify--"); Go. SetActive (true);}
Dynamic Create
Awake and onenable are called first, and there is no chance of invoking initialization before this.
However, there are workarounds to save prefab as inactive and activate after initialization:
Unity script Execution Sequence test in the Hierarchy Panel 2