Question by
Develax · Aug 08, 2019 at 08:07 AM ·
editor-scriptingscene-switchingdestroy object
Editor: detect destroy object event when unloading scene
Is it possible to know in the Editor that OnDestroy()
is triggered because the scene is closing? IOW I want to differentiate it from the case when OnDestroy()
is triggered due to removing an object from the scene.
I tried to subscribe to EditorSceneManager.sceneClosing
to set a flag and then use it in OnDestroy()
but this event didn't work.
Comment
Answer by Mariusz-Born7 · Dec 10, 2021 at 05:29 PM
I am using both EditorSceneManager.sceneClosing and EditorSceneManager.sceneClosed and it works.
The order of events is: sceneClosing ... OnDestroy OnDestroy ... sceneClosed