Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Position of objects in animation is reset after TimeLine finishes

Discussion in 'Timeline' started by mrCharli3, Oct 23, 2018.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    I use animations to move boulders into place for the player to jump on.
    I wanted to trigger the animation from a TimeLine, so I added it and it plays like I want it to.

    But the animator resets when the TimeLine is done, I want it to behave like it would if I had set a transition boolean = true in the animator, i.e it stays at the end of the animation so the boulders positions don't reset.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Which version are you using? And are you using root motion on the boulders' animators?
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    Unity version 2018.2.12f1, no root motion, but I've tried with it too. The anim always goes back to the default state once the timeline is finished.
     
    david-mal likes this.
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Do you have an animator controller attached? It sounds like something else might be putting it back to default.
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    I dont have a an animator controller attached.

    The animator has a default state that is empty, and the animation I play from Timeline, no transitions or anything.
     
  6. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    Here is some screenshots:





     
  7. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Does the Waterfall Cave object have an animator controller? Is that what the last screen shot is?

    If it does that would explain the behaviour. Timeline interrupts the state machine, but returns to it when the timeline completes.
     
  8. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    Yeah that does explain it, but what do I do to fix that? I cant't just remove the animator? Then it won't play anything.
     
  9. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If the waterfall is not using root motion, then maybe the simplest thing is to animate a parent object using timeline instead.
     
  10. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    I am already animating a parent object. that is, the Animator is attached to an empty parent, that contains all the children I move in the animation.

    I am changing the position of it's children. The issue is that the position of these children gets reset when Timeline is over. Surely it's a pretty common scenario to play an anim where you don't want it to reset once it's over?
     
  11. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    So, it depends on which children your idle and your 4_Waterfall animations are writing to. Maybe disable writeDefaults on your idle state if it's not writing the same children as 4_Waterfall.

    It is a common scenario to play an animation that isn't reset, which is what root motion is for. Root motion only applies to the parent transform, all other transforms get the local position and rotation applied exactly as recorded in the clip, or what the default values are. So if you are a playing an animation after the timeline, new values are being written. writeDefaults, will tell the state to not write values that aren't explicitly animated.

    I hope that helps.
     
  12. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    Thanks. Unfortunately I've tried all possible combinations of write default on/off with root motion on/off. All have same effect.

    My Idle animation is literally just an empty animation state, it is not connected to a motion.
    I mean I could just write a Script that sets a trigger in the animator through Timeline, but I would like to be able to do it how it's intended.
    Somewhere there is something that resets the position of all child-objects in the animation when the Timeline is destroyed and the animation goes back to "Idle". Which does make some sense, but I cannot find any solution to my issue.

    Is there any info I've missed sharing with you, that might be causing this effect? Or anything that would help you determine a solution?
     
    Last edited: Oct 30, 2018
  13. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    If I completely remove the Timeline and just run the animation, then transition into the Idle state after playing the animation, it works (no positions reset). So it's something being caused by Timeline. Think I'll just stop using Timeline, only giving me headaches. But if you can think of a reason do let me know, I feel like it could be such a poweful tool.
     
  14. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    My only suggestion is to file a bug. It may be a simple solution, but it's hard to tell without all the information that an actual repro case provides.
     
  15. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    To repro:

    • Create an animator with an empty default state.
    • Attach animator to empty parent object.
    • Add a few child objects to parent, just simple 3d cubes.
    • Create anim that moves positions of animator children objects, in my case I have 6 child objects that I simply change y-value on.
    • No animation transitions.
    • Create a Timeline that simply plays the animation created in above step.
    This does (in my case) lead to the animation returning to the default state once the Timeline is finished, and thereby resetting the position of the child-objects.
     
  16. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Ok, that's an easy repo, and it is expected behaviour. The reason is the animator controller always writes _something_, even if write defaults is off (write defaults just updates the default values, which timeline never does). Animating the root of the object when root motion is enabled is the exception, exactly for this reason.
     
  17. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    Ok, so then this type of anim will never work with Timline (an empty parent that only animates children), correct?
    Since using root motion on the parent won't affect the children. At least not in this case.
     
  18. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    I wouldn't say never, but it's not on the roadmap. The issue isn't really timeline, it's the controller overwriting what timeline has done. Using an avatar mask on the controller to prevent the controller from writing to those children might work, if the controller doesn't need to animate the children.

    Otherwise giving an option for timeline to write default values is something we could investigate.
     
  19. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    657
    Okay, either way, thanks for all the help! :)
     
  20. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    72
    Yeah, I've run into the same issue.

    All I want to do is slam a door. Using Timeline, I create a track with the two positions and add a nice door slam audio clip at the end. I play it, the door slams and the audio clip plays... but then the door snaps open again!

    This really feels counter-intuitive to me. Is there no way to simply say "when the timeline is done, leave things as they are"? I would think that would be the default case, or at least an option.
     
  21. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    72
    Not sure if this is a newly-added feature, but it does solve the problem I was having...

    In the PlayableDirector component, there's a "Wrap Mode". The default is none, but if you change it to Hold then the values that were changed by the animation stay changed.

    I can now make the door slam, so I'm happy. :)
     
    CackeMuffin and wido2000 like this.
  22. tektonspace

    tektonspace

    Joined:
    Dec 28, 2016
    Posts:
    18
    @BernieRoehl
    I love you man
    you made my day. Been manually adjusting timelines to fix the issue.
     
  23. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    286
    For anyone reading this: the PlayableDirector WILL NOT RELEASE your model under "Hold" mode. Meaning if you are animating a car, that is supposed to move via a script after animation finishes - it WILL NOT MOVE! Manually stopping/disabling the Director at this point will lead to the standard teleport back.
     
    Last edited: Aug 22, 2020
    tektonspace likes this.
  24. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If there is an animator controller on the door, then that could be the reason it is snapping back. If you are using a custom track, then you need to explicitly code it to snap back (as opposed to leaving it). Otherwise when the timeline finishes it just relinquishes control, or nothing writes to the object.

    As @cubrman mentions, the hold simply means the timeline continuous to play the last frame, overriding the animator controller.
     
  25. bradbecker

    bradbecker

    Joined:
    Dec 26, 2014
    Posts:
    111
    @seant_unity so if there's nothing else trying to control an object (animator controller, etc) then everything will be left as it is on the last frame and timeline will stop writing to the objects? Is that Wrap mode set to continue?
     
  26. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    That would be the behaviour with 'None'. With 'continue' the behaviour is to effectively extend the clip to the next clip/end of the timeline. Continue is a bit misleading in the name, so I'll try to explain the difference.

    The wrap / extrapolation mode is done by modifying the time passed to the playable representing the clip. For example, if the playhead is 2 seconds past a 5 second clip with
    • None - the clip has been deactivated, no time is passed
    • Loop - '2' is passed as the time to the clip
    • Hold - '5' is passed as the time
    • Continue - '7' is passed as the time. For animation clips, this isn't obvious because the animation clip itself may be less than 7 seconds in length and may loop. But for something like a particle system this could allow for a trailing off of existing particles.
     
  27. TheSwanCollective

    TheSwanCollective

    Joined:
    May 6, 2016
    Posts:
    25
    Now that we're all talking about Timelines and State Machines ... is there already a clean and nice way to transition between the two?
     
  28. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    You can ease-in/out your first and last clips on your animation tracks. Your timeline will blend from/to the state machine as it starts and finishes.
     
  29. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    176
    Hi @seant_unity , thanks a lot for answering the questions here.

    Now to add my question to the pile ;)

    I am animating the "Minimum Ortho Size" float variable on a Cinemachine Virtual Camera to zoom the camera during my cutscene (2D project).

    I'm using the 'recording' with an Animation Track. The Cinemachine Virtual Camera binding doesn't use an Animator Controller (it just has the Animator on it for Timeline).



    After the timeline finishes playing through, the Minimum Ortho Size value reverts to its value before the timeline started. How can I make it stay at the final value from my 'recording'?

    Thanks for any help!
     
  30. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Hmm..I made a setup to test this, because I can't explain why it's reverting. I wasn't able to reproduce the behaviour you observe. Is it possible there is something else writing to that virtual camera, like another timeline?

    In the editor it will revert once the preview is released, but in playmode it should stay that way.
     
  31. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    176
    Hey @seant_unity, thanks a ton for the response - you are correct that it was something in my code setting the value. I've been testing out a lot of types of Tracks with timeline and wrongly assumed that the value getting reverted was due to the track. Your assurance that it *shouldn't* be getting reset did lead me to find my code that was accidentally setting it. Thank you!
     
  32. TheSwanCollective

    TheSwanCollective

    Joined:
    May 6, 2016
    Posts:
    25
    Thanks @seant_unity! Every insight is most valuable to us :)

    One more thing (not concerning Timeline - only Mecanim):
    Say I have a Mecanim animation playing a long idle clip of an NPC. The player interacts with the NPC, causing the NPC animator to jump to a second short animation clip. Now clip2 finishes and per default goes back to the idle clip.

    Is there a way to return to the position of the idle clip, when it was interrupted and avoid it to start from the first frame? Since the idle animation has a distinct beginning, it would seem more natural, if the idle clip wouldn't always reset, but continue from the interrupted point in time.

    Any chances?
     
  33. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    I'm not a mecanim expert so I may be missing something completely obvious. Maybe try using an animation event on the idle clip, or at the end of clip2, to reset it's position.

    Or use some combination of using a parent GameObject to position the NPC, and turning the root motion flag on the animator off, at least during the idle animation.
     
  34. TheSwanCollective

    TheSwanCollective

    Joined:
    May 6, 2016
    Posts:
    25
    Thanks so much for your reply Sean, what an epic service to be taken so seriously!!

    Unfortunately what I meant was more like this:

    • Idle animation is 10 seconds long
    • At a random point in time we switch to animation 2, for example at second 5
    • After animation 2 has played, resume idle animation from second 5 (not from start) - meaning, remember when the transition occurred and return to that point in time
     
  35. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Ah, I see. I'd recommend posting that on the anim forums actually. I can think of ways to do it - which require scripting - but you'll get more expert eyes than mine there for mecanim, and hopefully people who have solved that problem before.

    Alternately this is possible using different timelines -

    Timeline 1 has an idle animation on a animation track with TrackOffsets (if you want it to always play at the same position), continuously plays on loop.
    Timeline 2 has anim 2 on animation track with SceneOffsets. Anim2 uses ease in and out to blend to the other timeline.

    Timeline 2 plays, and has signals at the end of the ease in and the start of the ease out that pauses and resumes timeline 1.

    Not sure if this works in your context or scales to all your use cases, but it's something to try.
     
    TheSwanCollective likes this.
  36. TheSwanCollective

    TheSwanCollective

    Joined:
    May 6, 2016
    Posts:
    25
    Oh wow! Haven't thought about using signals for this purpose. So there are scripting commands to pause and resume a timeline I suppose?

    Thanks for your elaborate answer and I'll post to the anim forum directly as well.

    Peace
    Felix
     
  37. sp-gillian

    sp-gillian

    Joined:
    May 8, 2019
    Posts:
    8
    Just want to add my voice to this thread: this behaviour of Timeline is DEEPLY undesired and unexpected. I don't think the behaviour we'd like is too unusual or complex: if Timeline sets the state of an Animator, leave it there. Is there any chance of this being implemented?
     
unityunity