Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Showcase Blending between Timeline AnimationTrack and Animator

Discussion in 'Timeline' started by tsukimi, Aug 6, 2023.

  1. tsukimi

    tsukimi

    Joined:
    Dec 10, 2014
    Posts:
    56
    Hello!
    I would like to share my technique to blend between Timeline's Animation Track output and Animator Controller's output.

    ezgif-4-aa69da5546.gif

    As you may know, if one set
    AnimationPlayableOutput.SetWeight()
    , then you can blend animations between different graphs. However, Timeline is also setting the output weight during the PlayableGraph evaluation as well, so simply setting weight out from PlayableGraph won't make any work, as for it will be overwritten by Timeline itself.
    So, what one can do, is to add another Playable to the graph, to re-rewrite the weight. An example is like this:
    Code (CSharp):
    1.     public class SetAnimationOutputWeightBehaviour : PlayableBehaviour
    2.     {
    3.         public float weight;
    4.         public List<AnimationPlayableOutput> outputList = new();
    5.  
    6.         public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    7.         {
    8.             // set weight
    9.             foreach (var output in outputList) {
    10.                 output.SetWeight(weight * output.GetWeight());
    11.             }
    12.         }
    13.     }
    If one add the PlayableBehaviour into the graph, the weight will be setted every frame.

    Here(Github) is the full script of the
    TimelineAnimationWeightSetter
    . Attach the script to the same gameobject of the Timeline(PlayableDirector), then you can set the weight of Timeline animation at any ratio. (same as the gif img above)
    You can leverage this technique to add systematical animation fading-in fading-out between Timeline and Animator, to make the transition look good.
     
    Invertex, catkin0718 and rawna like this.