Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Animator/States on Timeline

Discussion in 'Timeline' started by lrasomattos, Oct 3, 2018.

  1. lrasomattos


    Aug 22, 2015

    Is there a way to control Animators or Animator States with the timeline? I have objects with complete customized animators, I would like to, instead of forcing an Animation clip, be able to set the State, or parameters of the animator using timeline.

    That would make things like looping animations, or single shot animations much easier to control and much more flexible. For example, in case a jump animation has it's length changed, I wouldn't need to go to the Timeline and adjust it's clip. Or I wouldn't need to spread idle clips through the whole track because I want the character to be breathing when it's not doing other actions.

    Also, when the Timeline pauses (in moments that I need to wait for player input, like dialogues) the character's states could stay the same (idle, crawling, etc), instead of having to force the animator to the state I want through messy Game Object activation etc.

    I am not sure it is implemented already, I just started using Timeline, but I couldn't find much info on how animator interacts with Timeline, and I read somewhere that they are both built over the same Playable APIs. So I imagine it could be something doable. Maybe implementing an Animator Track where you can set Parameters on the Clips, or even force the animator to desired states? Any thoughts, ideas or suggestions on how to achieve it?
  2. Predulus


    Feb 5, 2018
    Did you find an answer to this?
  3. lrasomattos


    Aug 22, 2015
    Unfortunately not... It kind of renders the Timeline impossible to use in situations where you're not making a "movie like" cutscene. I couldn't understand how it's expected to be used in more interactive sequences.

    To me it's obvious that it would be perfect for creating "Mass Effect - like" dialogue sequences, and at the same time, impossible
  4. Yuchen_Chang


    Apr 24, 2020
    You can write custom timeline track and clips for more general animations, something like
    Code (CSharp):
    1. [Serializable]
    2. public class AnimationBoolParameterClipPlayable : PlayableBehaviour
    3. {
    4.     [SerializeField] private string boolParameterName;
    6.     private Animator outputAnimator;
    8.     public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    9.     {
    10.         outputAnimator = playerData as Animator;
    11.         if (outputAnimator == null) return;
    13.         outputAnimator.SetBool(boolParameterName, true);
    14.     }
    16.     public override void OnBehaviourPause(Playable playable, FrameData info)
    17.     {
    18.         // this is called when currentTime get outside of the clip... including when scrubbing
    19.         if (outputAnimator) {
    20.             outputAnimator.SetBool(boolParameterName, false);
    21.         }
    22.     }
    23. }
    This will set the target Animator's boolParameterName to true when playing the clip, and revert to false when getting outside of the clip. Note that besides the above code, you'll have to write your own track and clip class. Also, if you want to preview the animation when editing, you'll have to write additional Editor code.

    (Maybe there's already somebody wrote this kind of code and release it as a library, it's not that hard.)