i have a C# property. ex.
public float MyValue { get; set; }
and i want to be able to animate it through an animation.
if i expose it as a field i can animate it, however i specifically want to animate it as a property.
has anyone had any luck exposing properties to the animator?
The Limitation is that unity needs a serialized member to represent it in the animation and properties aren’t serialized.
You may be able to what you want by using OnDidApplyAnimationProperties() ( Help please with Animation Component public properties custom inspector. ), manually checking for changes and applying your property logic.
yes i stumbled onto that myself. however that would mean that i have to double by fields 1 for the default state and 1 to be able to animate. i also then have to trust whoever is making the animation not to modify the default state variables.
maybe encapsulating those fields with a class could work (that tracks the changed state). That way you can write a custom propertydrawer to deal with those cases
If anyone else stumbles across this you can pretty much get what you need by giving the backing field of the property the SerializeField attribute. In front of the property (which must have a setter) just add [field: SerializeField] float MyValue {get;set;}
Note: You can make the setter private even though the property is public. This might help you limit what parts of your project can alter the value. Since the OP here was trying to animate it through the Animation system, making the setter private is wise.