Search Unity

Animation won't transition immediately

Discussion in 'Animation' started by Paulprog16, Jul 29, 2019.

  1. Paulprog16

    Paulprog16

    Joined:
    Apr 20, 2016
    Posts:
    54
    Hello,

    I am trying to transition from one animation into another. However, I need the first animation to finish playing completely before the second animation can start (each animation starts by pressing a different keyboard button).

    I have tried both bool and trigger, but I have the same problem with both: when I press the button to trigger the second animation anytime AFTER the first one is finished playing, the second animation gets triggered sometimes immediately, but sometimes only a second later, which is an enormous delay.

    I know the typical advised solution is to uncheck "has exit time", but that won't work in my case, since I need the first animation to play fully before it can transition to the next one.

    Is this a Unity bug by any chance? I can see in play mode in the animator window that the first animation has fully played (blue bar complete and static) before I press the button to trigger the second one, so I don't see any reason for the triggering of the second one to be delayed at all.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It's entirely possible that it's a bug or some obscure feature is interfering for some reason which nobody knows. That's just what you have to deal with when using Animator Controllers. When you encounter something like this it's rarely clear what the actual problem is, so you just try every combination of settings you can think of until something works. And you have no real way of debugging the logic its using.

    The simplest solution is probably to write a hacky script that gets the current state information every frame and manually checks the time to call CrossFade instead of setting a parameter and hoping that it will do what you want.

    Or if you're interested in finding a better system, you should check out my Animancer plugin. When you tell it to play an animation it will actually play that animation. It almost seems like magic when you compare it to Mecanim.
     
  3. Paulprog16

    Paulprog16

    Joined:
    Apr 20, 2016
    Posts:
    54
    So considering this kind of bug, which is not a minor one, is it possible to avoid the Animator Window altogether and control all the animations and transitions directly from script?
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Yes, sort of.

    If you keep using Animator Controllers, you will need to use the Animator window to set up states, but you can do all your transitions in code by calling CrossFade.
     
  5. Paulprog16

    Paulprog16

    Joined:
    Apr 20, 2016
    Posts:
    54
    Thank you.

    Can I have a word from an admin or mod on whether this is a bug or maybe I am missing something?

    Thanks!
     
  6. MusArmy

    MusArmy

    Joined:
    Mar 31, 2019
    Posts:
    1
    2 years later and I just encountered that bug, cannot fix it for the life of me.
     
  7. FabioZocklabs

    FabioZocklabs

    Joined:
    Jul 11, 2019
    Posts:
    17
    I also encountered this bug.
    When the animation finishes, and the condition to progress is already true, the transition is always triggered immediately.
    Else it's triggered after a seemingly random offset, but I think it's not random. It's a duration up to the duration of the playing animation. So I think, it will check once per cycle of the animation.
     
  8. FabioZocklabs

    FabioZocklabs

    Joined:
    Jul 11, 2019
    Posts:
    17
    I found a solution: After the animation is finished, it will enter a new state without a condition.
    This new state should look the same as the end of the other animation. For example making a new animation having a single keyframe.
    This new state will not have an exit time, but the condition.