페이지

2023년 7월 5일 수요일

When are All GameObject Awake(), OnEnable(), Start() called?

 1.

ExLifeCycle script is attached into All GameObjects (ex: Parent, Child1, ... )



public class ExLifeCycle : MonoBehaviour
{
private void Awake()
{
Debug.Log($"{name}:Awake");
}

private void OnEnable()
{
Debug.Log($"{name}:OnEnable");
}
void Start()
{
Debug.Log($"{name}:Start");
}
}


When Playing, the follow logs comes
----------------------
Child1:Awake
Child1:OnEnable
SubChild(1):Awake
SubChild(1):OnEnable
Child1(3):Awake
Child1(3):OnEnable
Parent:Awake
Parent:OnEnable
Child1(2):Awake
Child1(2):OnEnable
.....
Child1:Start
SubChild(1):Start
...


the calling order of GameObject Awake,Enable is not fixed, and random.
and After All gameObject OnEnable() are called, Start() of all are called.


2.


when playing unity in this case, 

SubChild:Awake
SubChild:OnEnable
Child1(2):Awake
Child1(2):OnEnable
SubChild:Start
Child1(2):Start

are not printed in console.
.






댓글 없음:

댓글 쓰기