- Home /
How can I determine if a GameObject is Dirty?
In the Editor, how can I determine whether or not a particular game object is dirty? By dirty I mean, it or one of it's component properties has changed, or it's moved in the hierarchy.
I see there is a SetDirty() method in EditorUtility but no corresponding GetDirty() method.
Using reflection I've tried calling the IsDirty() method of EditorUtility, but this returns false when I have a change to my object (name changed and transform changed).
I've also tried calling/accessing the following with reflection - UnityEditor.GameObjectAndHierarchyChangeTracker.SetTrackedGameObjects() - UnityEditor.GameObjectAndHierarchyChangeTracker.ClearDirty() - UnityEditor.GameObjectAndHierarchyChangeTracker.isDirty
This tells me when a hierarchy change has occurred by not whether the game object itself or its components have changed.
I know there is EditorApplication.SaveCurrentSceneIfUserWantsTo(), but I need to check if a subset of objects have changed, because I am implementing a layer system that uses sub-scenes to allow one person to checkout and lock a layer at a time (ie: scene collaboration)
Apparently, there is nowhere to hook your code natively ( check the answers/comments on this : http://answers.unity3d.com/questions/695682/get-if-any-component-in-gameobject-has-changed.html ), the only painful solution would be weaving :/
Another simple solution would be to force your user to lock/checkout the layer they are working on, and only update the checked-out layers information when saving the scene ?
This isn't an official answer, but one way of doing this is having a bool (maybe objectIsDirty) that starts out as false. Anytime you call a function that would make the object dirty, you could just set 'objectIsDirty' to true.