Search Unity

How to stop Timeline from going back to original position after playing?

Discussion in 'Timeline' started by msmithUnity, Dec 17, 2018.

  1. msmithUnity

    msmithUnity

    Joined:
    Jun 19, 2015
    Posts:
    12
    Hi,

    I'm using the new TimeLine to run a series of animations. I run it through a script, however when it completes, all the game objects that moved as part of their animation go right back to their original positions before the animation was played. How do I prevent this so that they stay where the timeline sent them?

    Thanks
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Turn on 'Apply Root Motion' on the gameObject's animator component.
     
  3. msmithUnity

    msmithUnity

    Joined:
    Jun 19, 2015
    Posts:
    12
    Just tried turning that on but it still goes back to original position. Is there other settings/configurations to look for? Thanks for the reply
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Are you animating the root transform, or a child? Root motion is only supported on the root transform. Otherwise 'absolute' values are getting written.

    Does your animator have a controller? I am assuming it does, because otherwise all transforms should stay where timeline last posed them.
     
  5. msmithUnity

    msmithUnity

    Joined:
    Jun 19, 2015
    Posts:
    12
    Hmmm....So I have a gameObject that has the animator component on it with a controller assigned and the apply root transform set and it has many child game objects. The controller has states that have animations assigned to them and use transitions with parameter conditions. The animations move the child game objects.

    I then tried creating a new timeline in 2018.3 and when I run that timeline in code, that's the one going back to original position. From your last question, yes I have an animator and controller, however they aren't linked in anyway to the timeline, which is probably why applying the root transform didn't have any effect. How do I link the animator to the timeline? Thought it wasn't possible yet?

    THANKS!
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If you play a timeline that animates a gameObject with controller, it takes over from the controller for the duration of the timeline. So they aren't linked necessarily, timeline just has priority. You can blend to and from (using ease in/ease out on timeline animation clips), but one can not directly reference the other.

    If root motion is applied, and the animations modify the root transform, then the root transform doesn't reset. You may need to change the import options on your animations so that they properly modify the root transform.

    The easiest way to tell is to check if the root transform is changing when your animations play. If the child transforms are only being modified then they will appear to reset when the timeline is done, because the controller is writing values exactly as they appear in the animations. Root Transform is the only transform where the values accumulate from animations, and only with the root motion flag enabled.

    I hope that makes sense. You can see the manual for information on how to set up root motion for animations if that's the problem.
     
    msmithUnity likes this.
  7. msmithUnity

    msmithUnity

    Joined:
    Jun 19, 2015
    Posts:
    12
    It does. Sounds like then since I have a timeline which modifies the position of a game object and that game object is a child of another game object that has an animator controller and animations, then my game object will return to it's original position because the animator takes back over after the timeline completes and sets it back to where it thinks it should be. I didn't expect that just because the game object whose position I'm modifying in the timeline doesn't have it's position modified in any of my animations that are in the animator controller.

    Well, long story short, once timelines are supported in animator controllers, my life will be much easier :)

    Thanks a ton for the help!
     
  8. AdamBebkoSL

    AdamBebkoSL

    Joined:
    Dec 9, 2021
    Posts:
    33
    @seant_unity I am also having this problem. I can't understand why, I chose "hold" in post extrapolate on my clips in timeline, but they snap back to initial position as soon as clip ends
     
  9. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    "Hold" is not the same thing as root motion described above. Hold just means the last value in the animation clip will be maintained if the animation clip ends before the end of the Timeline. Once the Timeline ends, "hold" is no longer relevant.

    Root motion is about changing the position (the root x,y,z Position value) of the character, so it is really moving the object (not just temporarily animating it). If enabled, the object is moved so retains its new position after the timeline finishes.
     
  10. AdamBebkoSL

    AdamBebkoSL

    Joined:
    Dec 9, 2021
    Posts:
    33
    I found the issue. It didn't affect runtime, only preview in timeline. What was happening is if the animation clip should 3.0 seconds long, because of floating point error, it's really something like 2.9999995438. Timeline sees that the clip is too short for the duration of 3.0s, and fills in this .0000001s making it actually try to loop back to the start of the clip. So it plays back the first frame of the animation and then holds there instead of the last frame. If I adjust the duration of the clip in timeline's clip inspector to 2.999s, it behaves as expected.

    Seems like a bug to me!
    This reproducible.
     
    Yuchen_Chang likes this.
  11. athensM

    athensM

    Joined:
    Mar 18, 2021
    Posts:
    10
    Can confirm this is happening for Unity version 2023.1.2f1, with Cinemachine package version 3.0.0-pre.7

    Can be reproduced reliably. The first playthrough of the timeline works fine. But replaying the same timeline after it has been played at least once will always cause it to loop back and play the first frame before ending. When the "Duration Mode" for the Timeline is set from "Fixed Length" to "Based on Clips", then this bug stops happening.

    Edit:
    This happens in runtime.