There are 2 cases when OnDestroy() is triggered in the Editor (the class should be marked with [ExecuteInEditMode] attribute):
Is it possible to differentiate these two cases within OnDestroy()? I tried to subscribe to EditorSceneManager.sceneClosing to set the flag and then use it in OnDestroy() but this event didn't work. Are there any other options?
A bit of an old question but it's the first result in Google so I thought I might share my approach.
void OnDestroy()
{
if(gameObject.scene.isLoaded) //Was Deleted
{
}
else //Was Cleaned Up on Scene Closure
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With