Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Optimization Challenge: how to build a PlayableGraph from 100’s of animation clips?

Discussion in 'Animation' started by CaseyHofland, Apr 19, 2023.

  1. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    610
    My case: I’m building a Clock / Time-of-Day system on the shoulders of the animation system. It’s flexible, great for version control, and previewable: a perfect fit.

    Now that the groundwork is there though, I want to optimize. Currently I have this:
    Code (csharp):
    1. // It’s a little more complex than this but this is the important bit.
    2. public class TemporalAnimation
    3. {
    4.     public clip;
    5.  
    6.     // start and end of clip correspond to 0:00 on the clock.
    7.     public void OnTimeChanged(float timeInterpolant)
    8.         => clip.SampleAnimation(gameObject, timeInterpolant * clip.length);
    9. }
    10.  
    11. // And I have this manager.
    12. public static class Clock
    13. {
    14.     public static TimeOnly time
    15.     {
    16.         // get;
    17.         set
    18.         {
    19.             timeEvent?.Invoke(timeInterpolant);
    20.         }
    21.     }
    22. }
    (Don’t flag me I know this is unoptimized as hell, used it for internal testing.)



    I understand that
    Playables
    and
    PlayableGraphs
    are the perfect man for the job here, but it’s all uncharted territory for me. Usually I don’t program with animations, it’s just that they slot so neatly into this asset.

    I imagine I’ll need to keep a reference in eg my static manager, something like
    Clock.playableGraph
    , that I then add
    Playables
    onto with
    TemporalAnimation.OnEnable()
    and
    TemporalAnimation.OnDisable()
    , but I don’t know if you can even get a clips Playable and I welcome any constructive criticism and advice on how to tackle this.

    I’d hope that then I can just call something like
    playableGraph.Evaluate()
    and remove the more expensive “OnTimeChanged” event.
     
    Last edited: Apr 19, 2023