Search Unity

Proper use & behaviour of MarkSceneDirty()?

Discussion in 'Scripting' started by hoperin, Aug 21, 2018.

  1. hoperin

    hoperin

    Joined:
    Feb 9, 2014
    Posts:
    52
    So diving into custom editor extensions has led me to bumping into issues when the modifications made to my scenes via editor scripts werent being saved because they weren't marked as dirty / serialized.

    I was able to get changes to one particular trouble object to record properly by using this code:

    Code (CSharp):
    1. var serializedObject = new SerializedObject(GameObject.Find("InkMaster").GetComponent<Scr_InkMaster>());
    2.         serializedObject.Update ();
    3.  
    4.         serializedObject.FindProperty ("inkAsset").objectReferenceValue = Instance.inkFile;
    5.         serializedObject.ApplyModifiedProperties ();
    However, I'm realising now that the problem is much more widespread and affecting lots of different objects and properties, not just this one. So I've been trying to get MarkSceneDirty(), as my understanding of it is that it just marks the entire scene as potentially modified, and should cause all my changes to be made?

    However, this doesnt seem to be doing anything at all.

    Code (CSharp):
    1.     static void SetSceneDirty(){
    2.           EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
    3.     }
    I'm calling it after all my changes are made, at the end of my editor script. Calling it at the start didnt seem to do it either. Am I missing something or fundamentally misunderstanding MarkSceneDirty()?