Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Speed multiplier ignores exit time

Discussion in 'Animation' started by gumboots, Aug 7, 2017.

  1. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Hi all,

    I'm using a multiplier for my speed value to play an animation in reverse. If I disable the multiplier everything works as expected, however with the multiplier enabled (and it being set to -1), the state continues to repeat over and over. I have tried setting Exit Time to both 0 and 1, but nothing lets it leave the state.

    However like I said, if I simply disable the multiplier checkbox, it transitions as expected.

    Any help is greatly appreciated!
     
  2. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    I've made a test project to show the issue:

    https://www.dropbox.com/s/xmq4qkiydasqq8g/Animation Issue Example.zip?dl=1

    So in the example, if you hold right click the stick should animate down, then once the animation is complete animate side to side. Once you let go of right click, the stick should animate up and then return to idle.

    The issue is two fold:
    1. The stick animation has to complete, you can't let go half way through and it animate from where it was.
    2. Secondly, the middle state ("Animate Out") uses a multiplier on it to determine whether it should the animation should play forwards or backwards, and it seems like the animation never finishes when it goes backwards, so on returning to idle, it gets stuck in the middle state.
    Thanks so much for your help!
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  4. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Reversing an animation clip with the speed multiplier on the state should work without restarting the animation from start.
    I did the feature myself for Tank project in 5.0 to animate the Tank track, so if it not working anymore it broken.

    But I agree a transition with an exit time on a state with a speed multiplier can be confusing, if the transition is already started and you start to rewind the clip, the transition time should continue to progress.

    Without investigating the issue with your project it's hard to tell you what you should expect.

    If you think the behaviour is wrong or buggy you should log a bug with all the details and we will investigate.
     
  6. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    Well to my thinking, if the exit time is 0, then it should leave at the beginning of the animation. Is that right? Therefore if I can reverse an animation, I'd probably also need to change the exit time at the same time, I'm not sure if that is possible? I can't figure out how to target a specific state, outside of fetching the currently active state. But determining that in script is like writing a separate FSM to monitor Mecanim's FSM, isn't it?
     
  7. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    unfortunatelly the answer is no
    https://docs.unity3d.com/ScriptReference/Animations.AnimatorStateTransition-exitTime.html
    You need at least one evaluation of your state before you can trigger an exitTime condition, meaning a transition with an exitTime of 0 will never be fired on the first frame.

    Many people are confused with the exit time condition, many user think that if the current time is past the exit time the condition will be evaluated to true which is not the case.

    So in your case why would you want to put an exit time condition if what you want is have a transition than can occur at any time?

    You can't change the exit time condition at runtime.

    No need to write a separate FSM, you can use a StateMachineBehaviour which can be attached to this particular state.
    https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.html
     
  8. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    So when the animation is playing forward, I want it to exit at 1, but when it's playing backwards, I want it to exit at 0 (of the normalized animation time). Or when playing it reverse, does '1' mean the start?
     
  9. NoiseFloorDev

    NoiseFloorDev

    Joined:
    May 13, 2017
    Posts:
    104
    He's setting the speed negative, so the time can reach frame 0 without being the first frame. When I looked at it in the other thread, it seemed like exit time transitions simply don't work when the speed is negative. They act like they're testing "current frame >= exit frame && previous evaluated frame < exit frame", eg. crossing in the positive direction, without reversing the check if the speed is negative.
     
  10. kyuskoj

    kyuskoj

    Joined:
    Aug 28, 2013
    Posts:
    56
    This is really awkward. no solutions?? 2018.3.0.f2
     
    ZombByeGod likes this.
  11. Lesnikus5

    Lesnikus5

    Joined:
    May 20, 2016
    Posts:
    131
    Faced this problem in 2020.3.3f1. HasExitTime does not work if the animation speed is set to -1 at runtime. Is there a solution? Is the error still not resolved?


    1.jpg
     
    Last edited: Jul 19, 2021
  12. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    92
    This problem also exists in 2021.2.12f1.

    I have a state with an animation, which plays at a Speed of 0.3.
    I have a single transition out of that state into a second state, with an ExitTime of 0.1, and a condition that is always true (I just created a new boolean parameter that's set by nothing, and thus remains always true).
    The transition has a fixed duration of 0.

    Yet the transition only plays AFTER the first animation has fully played, although it should play at 10% given the exit time of 0.1. I tried changing the duration, enabling/disabling the fixed duration, but nothing seems to work...

    Here are a few screenshots:
    upload_2022-12-21_16-19-14.png

    upload_2022-12-21_16-20-38.png

    upload_2022-12-21_16-21-42.png

    EDIT:
    I believe I found the solution, of which I am not sure whether its indented behavior or not:
    Apparently the exit time is not evaluated at all when the transition TO the state that fails to transition is still blending to that state. In other words, if you want to exit a state at 10%, but your transition to that state ends its blending at 30%, your exit time will be ignored and effectively treated as Exit Time = 1.

    upload_2022-12-21_16-36-5.png
     
    Last edited: Dec 21, 2022