Use AnimationCurve to animate a property?

Hey guys. I have a system which generates some AnimationCurves, using .SetCurve assigns them to an AnimationClip, which is then played on loop. It works fine, although I haven’t been able to animate properties with custom get/setters.

I have a variable called Distance, which, when changed, updates the size of a BoxCollider2D component. This works when either set directly ‘Distance = 10’ or via Reflection (which I suppose is what AnimationCurves use). Problem is, that I’m guessing, that AnimationCurves use FieldInfo to to cache the Reflection and not PropertyInfo, which makes get/setters with side effects not work.

To sum up:
Am I right thinking that Curves only support fields?
If no, then what’s causing the issue - the solution?

I’m open to any other ideas too.

Also, if you know of a way to detect variable change, which doesn’t involve a get/setter, then I’d be pleased to now.
I thought about caching the old value and than have an Update loop running, but I’m trying to optimize as much as possible and having a loop running just to check if a variable has changed seems kinda ridiculous to me.

public float Distance 
{
	get
	{
		return m_Distance;
	}
	set
	{
		if(m_Distance != value)
		{
			m_Distance = value;
			BoxCollider2D b = GetComponent<BoxCollider2D>();
			b.size = new Vector2(m_Distance, b.size.y);
			b.center = new Vector2(m_Distance / -2, b.center.y);
		}
	}
}
public float m_Distance;

Thanks,

–David

The solution is the hidden unity callback

public void OnDidApplyAnimationProperties() {}

It is called whenever a property is update in your component.

Another better known solution is to use something like

public int MyProperty;
private int _myPropertyCache;

void LateUpdate()
{
   if (MyProperty != _myPropertyCache)

    {
       Debug.Log("some change happened this update);
       _myPropertyCache = MyProperty;
    }

}