Get dirty state from a scene

Hi Uniteers, I am currently looking for the possibility to identify whether the current open scene is dirty or not.

What I am trying to develope is an editor tool that can inform multiple members on a team if someone have made a change to a scene. This is to avoid that multiple members are working on the same scene file, and hopefully prematurely catch an upcomming merge error related to version control such as when using Git / Asset Server. However, I am required to inform my editor script when the scene becomes dirty, but I can’t seem to find any methods which does that. Any advice, or am I missing something?

Workaround Solution: Thanks to @arelian11

IssueTracker:

Workaround Solution:

Attach this to a game object in your scene and save the scene.
Now every time you compile and if you scene is marked dirty it will be detected by this code and logged.
Click on the logged line in console and it will point you the offending gameobject that is marking the scene dirty.
Next, check the parent of the target game object of grandparent or so on…and if you see that it has a scroll rect, fix the floating values on the scroll rect to be rounded integers instead of floating values.

This will fix the bug and the scene won’t be marked dirty anymore.
My scene had 30 or so objects that had this problem fixed it in 5 mins. No more version control bloat and more problems in sharing scene file.

`

public class SceneDirtyFlagChecker : MonoBehaviour 
{ 

static SceneDirtyFlagChecker() 
{ 
Undo.postprocessModifications += OnPostProcessModifications; 
}

private static UndoPropertyModification[] OnPostProcessModifications(UndoPropertyModification[] propertyModifications) 
{ 
Debug.LogWarning($"Scene was marked Dirty by number of objects = {propertyModifications.Length}"); 
for (int i = 0; i < propertyModifications.Length; i++) 
{ 
Debug.LogWarning($"currentValue.target = {propertyModifications_.currentValue.target}", propertyModifications*.currentValue.target);*_ 

}
return propertyModifications;
}
}
`

Currently (4.5.4f1) I see no public API to access dirty state of an object.

However, via reflection you can access bool EditorUtility.IsDirty (int instanceID).

I know this is a somewhat old question, but I’ve found a possible answer. I thought I’d post it here for reference.

It turns out, there is a callback that Unity triggers whenever an object is modified anywhere in the editor. It doesn’t apply to the scene alone, but it will track scene changes.

public static bool sceneIsDirty = false;

static SceneDirtyChecker() {
    Undo.postprocessModifications += OnPostProcessModifications;
}

static UndoPropertyModification[] OnPostProcessModifications(UndoPropertyModification[] propertyModifications) {
    sceneIsDirty = true;
    return propertyModifications;
}

All you have to do is manage the sceneIsDirty flag, and you’re good to go!