Unity API for checking if an object was modified

Is there any API that Unity provides for determining whether an object was edited (e.g: some value changed in its inspector) ?

There is a method called EditorUtility.SetDirty that accepts an Object and sets it as dirty.

Is there a method for determining if a given object is currently dirty?

Hey There,

You can use OnValidate(). That functions gets called whenever something changes in the inspector.

This will not tell you if something changed in the scene. You can hook into the AssetModificationProcessor to see when something is going to be saved if it was dirty.

I am not sure if there is a direct way to check if an Object is dirty.

Regards,

If you want this at edit-time and you like hacks, this looks like it should work (not tested)

bool isDirty = (bool) typeof(Editor).GetProperty("isInspectorDirty", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(myEditor, null);

31862-dirty.png

EditorUtility.IsDirty