Search Unity

Help Wanted Can you animate C# properties using the Animator component?

Discussion in 'Animation' started by Sinterklaas, Aug 10, 2021.

  1. Sinterklaas

    Sinterklaas

    Joined:
    Jun 6, 2018
    Posts:
    59
    So I have a bunch of properties in a C# script, of the following form:
    Code (CSharp):
    1. [SerializeField] _property;
    2. public property
    3. {
    4.     get { return _property; }
    5.     set
    6.     {
    7.         _property = value;
    8.         DoUpdate();
    9.     }
    10. }
    The DoUpdate function does a bunch of behind-the-scenes stuff that needs to happen whenever the property is changed.

    I want to animate these properties using the animation system, but I'm not sure if this is possible? I've only been able to animate the serialized field directly, and the C# property does not appear in the Animation window under the 'Add Property' dropdown menu, only the serialized variable.

    Doing it that way means that the DoUpdate() function never gets called however. As a result, I would have to manually check if the field has been changed every update. Which I would rather not do, as I'm going to have a lot of these properties on many objects.

    Is there a way to have the Animator use my C# properties, instead of directly addressing the serialized variables?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,803
    No, it can only do fields.
     
unityunity