Animation doesn't update custom setter!?

Hey,

I’m trying to animate a material property via the animation window. Ideally I’d like it to be a setter (via a custom script) so I won’t have to check in an Update to know if the value changed.
Since getter/setter aren’t displayed in the Inspector, I made a CustomEditor script but it doesn’t work via the animation window:

using UnityEditor;

[CustomEditor(typeof(BrushMaterialControl))]
public class BrushMaterialControlEditor : Editor {

    SerializedProperty clip;

    void OnEnable() {

        clip = serializedObject.FindProperty("clip");
    }

    public override void OnInspectorGUI() {

        EditorGUI.BeginChangeCheck();

        DrawDefaultInspector();

        clip.floatValue = EditorGUILayout.Slider("Clip", clip.floatValue, 0.0f, 1.0f);

        if (EditorGUI.EndChangeCheck()) {
        
            ((BrushMaterialControl)target).Clip = clip.floatValue;

            clip.serializedObject.ApplyModifiedProperties();
        }
    }
}

using UnityEngine;

[ExecuteInEditMode]
public class BrushMaterialControl : MonoBehaviour {

    [SerializeField, HideInInspector]
    private float clip = 0;

    public float Clip {

        get { return clip; }

        set {

            Debug.Log("ok");

            if (value != clip) {

                clip = value;
            }
        }
    }
}

When I change the slider via Inspector the Debug Log is output, but not when it’s modified via the animation…

Any ideas?

In the Animation you are setting clip. While in the Editor script you are setting Clip.

Thanks for the answer.

The script above works fine even manipulating directly the value via Inspector panel. However when changing clip value via the Animation window the setter is never called. Is it an expected behavior from Unity?

As I said, the Animation sets clip, not Clip.
In an Animation you can only animate serialized fields. Not properties.