Search Unity

Question How to make timelines pick up from where the previous timelines left off?

Discussion in 'Animation' started by ICNCdev, Aug 26, 2021.

  1. ICNCdev

    ICNCdev

    Joined:
    Aug 12, 2021
    Posts:
    6
    I am attempting to create a choice-based game. Every choice you make plays a different timeline cutscene the moment it is made, and at the end of a cutscene, the choices are displayed and the cycle continues. The timelines may be as simple as a single movement lasting 10 seconds with some text, or it could be a 5-minute long timeline with many tens of sprites moving at once.
    So it goes:
    Choice made => Cutscene plays =>Cutscene ends => Repeat

    What I would like to have is where I can designate a "Parent Timeline" that timelines can "pick up from" when I make child Timelines following from it.
    For example:
    Say I make a timeline "Circle Moves" where a circle moves from xyz(0,0,0) to (10,0,0).
    I would like to make a timeline that starts that same circle off from xyz(10,0,0) the instant I make it, so I can make the timeline continue from that point onwards.
    However, this would not be limited to one timeline. I'd like to have multiple timelines potentially be able to start from where the parent timeline ended, so that each choice maintains its continuity placement-wise with the parent timeline.
    Furthermore, each "Child Timeline" that follows from a choice would need to be equally capable of being a parent timeline that can have children timeline, and so on and so forth.

    The trigger for these timelines would be provided from the AnimatorController as I have that set to control what timeline is currently playing. My issue is I would like multiple timelines to inherit state from the prior timeline.

    Edit: The question is how could I make Timelines inherit state
     
  2. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    78
    Save the normalized time of your animations. Set those normalized times when you pick it back up.

    Code (CSharp):
    1. float normalizedTime = myAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
    2. ...
    3. int hash = anim.StringToHash("MyAnimation");
    4. anim.Play(hash, 0, normalizedTime);