Search Unity

How To Detect Exiting Prefab Mode?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dreamteck, Jan 3, 2019.

  1. Dreamteck

    Dreamteck

    Joined:
    Feb 12, 2015
    Posts:
    336
    I'm exploring the new prefab workflows in 2018.3 and the editor tools we have at our disposal. I want to know if it is possible to detect when the user is exiting the prefab edit mode in the editor.

    So far I tried:
    EditorSceneManager.sceneClosing:
    https://docs.unity3d.com/ScriptReference/SceneManagement.EditorSceneManager-sceneClosing.html But it seems like the prefab scene does not count as an actual scene and so the event is never called when exiting the prefab edit scene.

    I then tried subscribing to:
    EditorApplication.hierarchyChanged
    https://docs.unity3d.com/ScriptReference/EditorApplication-hierarchyChanged.html

    But it gets called after the prefab has already been closed and I need to run some code before the prefab scene is closed so that changes get written to the prefab upon exit.

    Anyone know how to do that?
     
  2. Dreamteck

    Dreamteck

    Joined:
    Feb 12, 2015
    Posts:
    336