[Feature] Show dirty state of assets in project browser

There’s a current issue in the new Localization package I’ve been trying out which raised the need for this feature. Assets are not being made dirty when they should be. It can be tedious to find out if an asset is dirty because you need to inspect the file in a text editor to see if anything has been changed.

I’d love to see a new feature in the Editor that shows the dirty state of assets like the inspector does with prefab instance overrides; a light blue line at the edge of the window.

5974574--641345--dirty.gif
Here’s a simple script script that shows this state. It’s ugly, probably very inefficient, but it does help isolate some of these “data not saved” issues

public static class SetDirtyMenu {

    private static readonly Color dirtyObjectColor = new Color(1f / 255f, 153f / 255f, 235f / 255f, 0.75f);

    #region Private Methods

    [InitializeOnLoadMethod]
    private static void Initialize() {

        EditorApplication.projectWindowItemOnGUI -= OnProjectWindowGUI;
        EditorApplication.projectWindowItemOnGUI += OnProjectWindowGUI;
    }

    [MenuItem("Assets/Set Dirty")]
    private static void SetObjectsDirty() {

        var objects = GetObjects();

        foreach (var obj in objects) {

            EditorUtility.SetDirty(obj);
        }
    }

    [MenuItem("Assets/Set Dirty", true)]
    private static bool ValidateSetObjectsDirty() {

        return GetObjects().Length > 0;
    }

    private static Object[] GetObjects() {

        return Selection.objects.Where(t => EditorUtility.IsPersistent(t)).ToArray();
    }

    private static void OnProjectWindowGUI(string guid, Rect selectionRect) {

        if (Event.current.type != EventType.Repaint) {

            return;
        }

        string path = AssetDatabase.GUIDToAssetPath(guid);

        if (AssetDatabase.IsMainAssetAtPathLoaded(path)) {

            var obj = AssetDatabase.LoadMainAssetAtPath(path);

            if (EditorUtility.IsDirty(obj)) {

                selectionRect.x = 0;
                selectionRect.width = 2;

                EditorGUI.DrawRect(selectionRect, dirtyObjectColor);
            }
        }
    }

    #endregion
}
9 Likes

That’s a great idea! Dirty assets cause a lot of trouble for us, when people forget to “Save Project” before committing assets to git.

The blue line looks nice, but it has a different meaning in the inspector (override). I think I’d prefer a * symbol at the end of asset name instead. The * would be consistent with how Unity communicates a dirty scene already. Other applications also use a * to indicate dirty documents too, so it’s well established.

The dirty state should propagate the folder hierarchy upwards. So you’d see “Assets*” if anything inside assets is dirty. In your example, it would display a line next to the “Tables” and “Assets” folders.

If it does not propagate upwards, it wouldn’t be that useful, because you can’t see whether an asset is dirty, unless you open the folder where that asset is located.

5976305--641654--upload_2020-6-13_18-10-8.png

17 Likes

Thanks for the suggestion! I’ll pass it on to the team.

5 Likes

Uhh, I would like this a lot.

2 Likes

me too

+1 I’m using the shortcut to reload assets because automatic script reloads make iterations slower - but sometimes I forget if I’ve already reloaded or not