Let’s say I have a scene with Objects in a flat hierarchy (cam,light,o1,o2,o3,o4,o5,o6).
Is there a defined object(!)-order in which their event functions are called? Let’s say the Start()-event. I wrote a test script which shows via Debug.Log(…) the order in which the objects get called,…
Start() and Update()-Order have the same order: Cam,Light,o6,o5,o4,o3,o2,o1.
OnApplicationQuit()-Order:Light,Cam,o5,o1,o3,o2,o4,o6.
Those orders stay the same among multiple starts/stops.Changing the hierarchy doesn’t effect the outcome. I would have expected some sort of tree-traversal of the hierarchy.
My problem is that I need to get in the first OnApplicationQuit(…)-call to set a certain flag e.g. on the root element(to prevent our huge scene from doing a clean dispose which takes some time and is not necessary on application exit)
Thx for the replys. We are using Zenject Depedency-Injection framework which also hooks on the OnApplicationQuit-call and cleans “disposes” all objects we use (and that are very many). Stopping the editor takes about 15seconds just for the disposing process. Disposing make sense to free memory during the game if you load a new level or such but all at once takes too long just for quiting afterwards…
So the plan is to set a static flag like QUITTING=true if you stop the application and check for this flag in the dispose-functions. But this variable have to be set before Zenject starts the dispose-process. That works one time and doesn’t another…
But can you confirm that there is no defined order of how the active objects get processed!?
I think I will alter Zenject itself even though I didn’t want to do that, but that might be for now the easiest solution.
The best way I’ve found to do this is to just duplicate the check-if-quitting behaviour in each component that needs it. Then I don’t have to worry about order.