I have a number of objects, A through F for this example, and I am seeing some behavior that is confusing to me when exiting a level or stopping play mode. The OnDisable/OnDestroy execution order is as presented:
A OnDisable
B OnDisable
C OnDisable
A OnDestroy
B OnDestroy
C OnDestroy
D OnDisable
E OnDisable
F OnDisable
D OnDestroy
E OnDestroy
F OnDestroy
Please find attached an example via the Unity console.
This presents a problem because I am referencing other components in OnDisable; however, they are sometimes already destroyed (I could check to see if the reference is already destroyed and then not touch it, but that is an ugly solution for a problem which should not exist). The script execution order for all of these components is the same.
Is there a proper workaround for this behavior?
Thanks.