Search Unity

EditorSceneManager.sceneSaved callback marks scene dirty. Can this be suppressed?

Discussion in 'Scripting' started by RecursiveFrog, Oct 27, 2019.

  1. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    In Unity 2018.4.11f1:

    I have GameObjects in my scenes that I use as markers for easy visual placement in my scenes. However, I do NOT want the visual components saved into the scenes. Therefore In my code, I have the following

    Code (CSharp):
    1.  
    2.             private void Start(){
    3.                
    4.                 EditorSceneManager.sceneSaving += OnSceneSaving;
    5.                 EditorSceneManager.sceneSaved += OnSceneSaved;
    6.            
    7.             }
    8.  
    9. // later ...
    10.  
    11.              private void OnSceneSaving(Scene scene){
    12.  
    13.                  // Remove things from scene before saving
    14.  
    15.              }
    16.  
    17.              private void OnSceneSaved(Scene scene){
    18.  
    19.                  // Re-add the removed things to scene
    20.                  // ... But now the scene is dirty again!
    21.  
    22.              }
    23.  
    Inside OnSceneSaving, I remove visual items from the hierarchy that should not be saved into the scene.

    Inside the OnSceneSaved callback, I restore the things I don't need to save into the scene, but in doing so I have marked the scene dirty. But I don't want the scene to be marked dirty! It doesn't have changes that I care about.

    Is there a way to suppress this, so that I can re-add the visual markers into the scene without marking the scene dirty?
     
  2. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    Resolved : The issue actually was with a different component in the scene. As it turns out, the approach above works just fine.
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618