Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Animating serialized class properties with animation clip?

Discussion in 'Animation' started by FeastSC2, Sep 12, 2018.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    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.

    Code (CSharp):
    1. public class ParentClass : Monobehaviour
    2. {
    3.     public ChildClass myClass;
    4.     [Serializable]
    5.     public class ChildClass
    6.     {
    7.          public float test;
    8.     }
    9. }
     
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    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.
     
  3. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,615
    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.
     
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    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.
     
  5. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,615
    FeastSC2 likes this.
  6. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    456
    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?
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,615
    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.
     
    FeastSC2 likes this.