How can I change properties by set function in Animation Editor

Hi, I recently using the animation editor in Unity3D controls several values in my script (MonoBehavior). I know that the animation editor in Unity3D can control the properties you exposed in Inspector, and I think maybe it obey the rule of property getset function in C#, so I create a MonoBehavior something like this:

public class Test : MonoBehaviour {
    [SerializeField] float _val = 1.0f; 
    public float val { 
        get { return _val; } 
        set { _val = value;  Debug.Log("value changed " + _val); } 

Then I create a AnimationClip adjust the Test.val from 1.0f to 10.0f in one second. As the picture shows:

alt text

In the game, I play this animation. What I expect is the Val can changed by animation and calling the set function to print the log. But it only changed the _val, so I guess the Animation Editor in Unity3D changes properties directly without checking if it has the get/set function.

My question is:

How can I let the Animation Editor changes properties by invoking their set function ?

Unity’s serialization system doesn’t work with properties at all. Unity only serializes fields / variables. Properties are actually just a special kind “methods pairs”. So you can’t really make Unity use your properties.

Unity now supports a special interface (the ISerializationCallbackReceiver) which allows your class to receive a callback whenever Unity serializes / deserializes your class. However that might happen more often than you think inside the editor.

The actual answer is to add a

public void OnDidApplyAnimationProperties() {}

It will be called by the animator on animations