OnApplicationExit Order

Quasimodem

New member
Hello, I'm struggling with a very tough bug on our project that has to do with Unity's ordering of OnApplicationExit(), which unfortunately seems to be completely random!

The main problem is that the BehaviorManager implements this method, which in turn disables a destroys and disables... some set of Behaviors that's not entirely clear to me. The problem occurs that we also want to implement our own OnApplicationExit() elsewhere that saves the state of the game to disk. If Unity decides to call our method first, everything is fine and the state is persisted. If Unity decides to call BehaviorManager.OnApplicationExit() first, then lots of state changes when our Behaviors are shut down (due to OnBehaviorComplete calls) and by the time we're able to persist our game state to disk, that state is not what we want.

I was hopeful I could use some combination of the Application.wantsToQuit or Application.quitting callbacks to pre-emt OnApplicationExit(), but no such luck. I can find no flag within Unity to indicate that the app is in the middle of shutdown.

My only hope would be that there is some way within BehaviorDesigner to skip the OnApplicationExit() logic and just handle it all myself. Is there any workaround here I could use for this purpose?

Thanks in advance -
 
Shortly after my post I think I've found a solution in subclassing BehaviorManager with a new class and implementing my own empty OnApplicationExit. This seems to prevent the base class call from happening. Thank you for not sealing BehaviorManager!
 
Top