Changing field value in OdinEditorWindow marks all scenes as dirty

Issue #404 resolved
Richard Baxter
created an issue

Unity 5.6.6, Odin 2.0.1

** NOTE: See comment for recreation steps **

Hi!

So I have a very strange problem in that my very simple window

public class TestWindow : OdinEditorWindow
{
    public bool wat;

    [MenuItem("TestWindow/TestWindow")]
    static void Open() { GetWindow<TestWindow>().Show(); }
}

And editing a field will mark all scenes as dirty.

I did do a lot of debugging and decompiling (sorry for poking in, this bug is really messing with us) that the scenes all get marked dirty in

public static void EndDrawPropertyTree(PropertyTree tree) in InspectorUtilities 

called from

protected virtual void DrawEditor(int index) in OdinEditorWindow

this line

propertyTree.Draw(applyUndo);

I noticed in EndDrawPropertyTree that you have this snippit of code (decompiled)

if (tree.ApplyChanges())
...
...
UnityEngine.Object target = (UnityEngine.Object) weakTargets[index];
if (AssetDatabase.Contains(target))
    EditorUtility.SetDirty(target);
else if (!Application.isPlaying)
{
    if (tree.TargetType.ImplementsOrInherits(typeof (Component)))
    {
        EditorSceneManager.MarkSceneDirty(((Component) target).gameObject.scene);
    }
    else
    {
        EditorUtility.SetDirty(target);
        EditorSceneManager.MarkAllScenesDirty();
     }
}

I'm not sure why it is that you need to mark all scenes as dirty if the property type is not a component (bear in mind I can't see what macros you might have in place or anything, I don't have the source). From what I can tell the tree just has one element in it, the TestWindow (which is the OdinEditorWindow)

If the property tree's type is not a component and this marks all our scenes (even if there are no changes). We often have 10 - 15 large scenes open at any one time and pressing ctrl-s forces a huge long save and this is making Odin Editor Windows unusable by us.

can you add, like, a

else if (tree.TargetType.ImplementsOrInherits(typeof (EditorWindow/ScriptableObject)))
{
    ... some code that marks the window or scriptable object as dirty but doesn't mark all the scenes as dirty because I don't get why we would want to do this
   ... I also saw that AssetDatabase.Contains(target) returns false for OdinEditorWindows
}

?

Comments (13)

  1. Richard Baxter reporter

    I also see that all EditorWindow's hideFlags are set to DontSave, but this is not checked before marking the target as dirty... don't know if this is important though

    Would also note that this is a project that has a lot of processes and such running in the background and OnGUI in various contexts, but we've never seen changing a property causing all the scenes to get marked

  2. Richard Baxter reporter

    Ah! This actually recreates now

    1. Fresh Unity 5.6.6 Project
    2. Import Odin 2.0.1
    3. Create same class as before
    public class TestWindow : OdinEditorWindow
    {
        [MenuItem("TestWindow/TestWindow")]
        static void Open() { GetWindow<TestWindow>().Show(); }
    
        public bool wat;
    }
    
    1. Create/Open multiple scenes
    2. Toggle the bool
    3. All the scenes get marked dirty
  3. Log in to comment