ちょっと意外な挙動だったのでメモ。
次のようなGameObjectがあったとして…

親であるGameObject (0)をDestroyすれば5つ全てのGameObjectでOnDisable()が呼ばれるが、GameObject (0)とGameObject (1)はDestroy直後に呼ばれるのに対し、GameObject (2)以下ではちょっと後になってから呼ばれる。
public class Main : MonoBehaviour
{
public GameObject go;
void Start()
{
Debug.Log($"{Time.realtimeSinceStartup}: ---- Before Destroy ----");
Destroy(go);
Debug.Log($"{Time.realtimeSinceStartup}: ---- After Destroy ----");
}
}
public class OnDisableLogger : MonoBehaviour
{
void OnDisable()
{
Debug.Log($"{Time.realtimeSinceStartup}: {name}.OnDisable");
}
}
環境
Unity 2021.3.16 LTS
Unity 2020.3.43 LTS
