Animating serialized class properties with animation clip?

I would like to animate with an animation clip the values of a serialized class within a class (using the animation window). How can I achieve this?

The code below is an example of a class where the test float cannot be animated with an Animation clip.

public class ParentClass : Monobehaviour
    public ChildClass myClass;
    public class ChildClass
         public float test;

Is there no way to make this work?
I'd have to make a major rewrite in my code for a worse structure if this really is impossible.

it won't work with aggregated class.

But if you change class ChildClass from class to struct it should work, we do support animation on aggregated struct but not on class. There is a technical detail behind all this but I do not know exactly the reason.

1 Like

Alright I’ll find another way then.
This is a bit of a related question but how can I detect through script when an animation clip is targetting an object with a one of my scripts?
Basically I want to know if a shader script is being animated with an animation clip and if it is, I want update the material, I only want to do this if I know it’s being animated because if not, it’s wasted resources.


1 Like

I did what you suggested, it's good but it's still not as precise as I would want it.
Maybe there's a way to detect if a script has had its exposed properties modified, in which case it would update? How would I know that, must I necessarily keep a copied version of the object to have something to compare it to?

you could try to use MonoBehaviour.OnDidApplyAnimationProperties().

This method is undocumented but should be called every time the animation system write into your monobehaviour.
Try to keep the workload of this function to the lowest possible as it can become quickly the bottleneck.


Hi there, is there any way to do this now? More easily than having to create a controller script on top ?