Search Unity

Scene.isDirty returning false after doing changes.

Discussion in 'Editor & General Support' started by Futurerobot, Mar 7, 2016.

  1. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    I'm setting up a script for buildpreparations, iterating through scenes from the buildsettings and making sure the correct objects are active (we tend to swap this around when working with them.)

    Code (csharp):
    1.  
    2. for (int i = 0; i < _scenes.Count; i++)
    3.   {
    4.   Scene _newScene = EditorSceneManager.OpenScene(_scenes[i].path);
    5.   if (_newScene != null)
    6.   {
    7.   Debug.Log("Loading scene: " + _newScene.name);
    8.   }
    9.  
    10.  
    11.   StageManager _stageMan = GameObject.FindObjectOfType<StageManager>();
    12.   if (_stageMan != null)
    13.   {
    14.   Debug.Log("Resetting stages in: " + _newScene.name);
    15.   _stageMan.Reset();
    16.   }
    17.   else
    18.   Debug.Log("No Stagemanager in: " + _newScene.name);
    19.  
    20.   if (_newScene.isDirty)
    21.   {
    22.   Debug.Log("Saving Scene: " + _newScene.name);
    23.   EditorSceneManager.SaveScene(_newScene);
    24.   }
    25.   else
    26.     Debug.Log("No Changes in: " + _newScene.name);
    27.  
    28.   }
    29.  
    This strangely enough gives the output
    Loading Scene Blabla.
    Resetting Stages in Blabla.
    No Changes in Blabla.

    The reset function that is run, changes the active state of several gameobjects in the scene. I can see it doing it in the editor when I run the script. Any ideas why the scene wouldn't be flagged as dirty?