Unregister Singleton Events before OnDestroy is called

Hi All,

I’m trying to unregister some event listeners when my object is been destroyed. The events are part of a singleton (using lazy initialisation), so when I want to unregister I just do something like:

Singleton.Instance.EventToUnregister -= EventHandler;

The problem is when I quit the application, the singleton is getting destroyed before my object. So when my object attempts to unregister the listeners, it creates a singleton object (as it has already been destroyed).I have only encountered this issue while quitting the game, but it’ll likely happen when switching scenes.

I know singletons and MonoBehaviour don’t go well together, but is there a way around this issue?

I think you can leave it without unsubscribing.The UnityEngine should do that internally when clearing its internal listener structure.