Search Unity

Animating class instance fields with Timeline

Discussion in 'Timeline' started by OhiraKyou, Oct 24, 2018.

  1. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Unity version: 2017.4.2f2 (64-bit)

    I have a MonoBehavior that has a serialized field of a Serializable custom class. The custom class has serialized basic fields that I want to animate.

    Code (csharp):
    1. MonoBehaviour
    2.     Serialized class field
    3.         Serialized float field
    4.         Serialized bool field
    5.         ...
    However, the class's fields are not recorded, and they really should be. So, assuming I'm not missing something and this hasn't been added in a future version, consider this a suggestion.

    In addition, I'm up for suggestions on how to get around this limitation. My current best idea is to animate a proxy MonoBehaviour that passes along its values to the instance field on the target MonoBehaviour.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    That is a known limitation of Unity's animation system. If you use a struct instead of a class those fields should become recordable.

    Alternatively you can write a custom playable with an animateable public field that simply writes the field value to the monobehaviour field. LightControlClip in the DefaultPlayables package is an example of that.
     
  3. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Thanks for the response and suggestions! It's important that this be a class in this particular case, because it's being passed by reference to act as a sort of data remote control. But, I'll definitely keep the struct option in mind for other cases.

    For now, I just used a proxy MonoBehaviour and had it pass along the fields. Although, playables are an interesting option as well, for more complex animations.