How to check if inspector object field was changed

I draw in the inspector property to ScriptableObject like this:


How can I detect when reference was added/removed in the inspector?

For eg. when I remove reference with DEL key, I would like to call an event or do sth.

@metroidsnes , you could do the following:

EditorGUI.PropertyField(r, sp, GUIContent.none);
if (EditorGUI.EndChangeCheck())
	// Do something when the property changes 

You can use MonoBehavior.OnValidate()

It runs whenever there is a change to a property of the component script it is in (I don’t know how it behaves when interacting with custom inspectors). It works in both runtime and design-time.

From there, you could check if the value has changed to null, and I suspect that would be similar to checking for a deleted value like you want.

you can check it with,check manual for more reference



Here is a simple system which let’s you keep track of changed variables and call functions if value is changed.

using UnityEditor;

public class FooEditor : Editor {

    public SerializedProperty value;

    void OnEnable() {
        value = serializedObject.FindProperty("value");

    public override void OnInspectorGUI() {
        // Get value before change
        int previousValue = value.intValue;

        // Make all the public and serialized fields visible in Inspector

        // Load changed values

        // Check if value has changed
        if (previousValue != value.intValue) {
            // Do something...
            Foo foo = (Foo)target;