Search Unity

Animator.CrossFade interrupts other active cross fade

Discussion in 'Animation' started by cjacobwade, Aug 11, 2019.

  1. cjacobwade

    cjacobwade

    Joined:
    Jun 8, 2013
    Posts:
    10
    Howdy,

    Running into an interesting issue when I use CrossFade to force my character into an animation state very soon after doing the same with another CrossFade.

    So at frame 10, lets say I call this:
    animator.CrossFade("Jump", 0.2f);

    Then if I call this within 0.2f of the first call, the animator pops to the called animation with no fade:
    animator.CrossFade("Dive", 0.2f);

    I've found a way around this by not using CrossFade and instead playing a bespoke animation state with a bespoke transition hooked up to the state I'm trying to fade towards, but obviously that's annoying.

    Is this the intended behaviour of Animator.CrossFade and why doesn't it make sense for a new CrossFade all to cancel the previous fade and start a blend from the pose at that moment?

    Cheers,
    Chris
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I know of a few semi-related issues, but none that I would expect to cause that particular issue:
    • Calling Play("Jump") then Play("Dive") in the same frame would play the jump state and ignore the second call.
    • If you just played the dive animation and it is still fading out, then trying to CrossFade back into it will not work (but again it just gets ignored rather than popping into the animation like you describe).
    • For some reason they decided that the default CrossFade should use normalized time instead of seconds, so that isn't actually 0.2 seconds, it's 20% of the length of the animation. I'm not even sure whether it's referring to the current animation or the one you're trying to transition towards. CrossFadeInFixedTime uses seconds.
    If you're interested in a better animation system where you don't have to deal with Animator Controllers and stupid issues like this, you should check out Animancer (link in my signature).
     
  3. MartinTV

    MartinTV

    Joined:
    Jul 15, 2012
    Posts:
    6
    Waaaay late to the party here, 8yrs, so might not be relevant BUT I cached the current state (on the 3rd layer), called rebind, then used animator.play to force the character into the animation they were just in with the normalized time value for the cached sate.


    Code (CSharp):
    1.  
    2.  
    3.         void RebindAndRestoreAnimator()
    4.         {
    5.             // Cache info
    6.             Animator anim = PlayerInfo.playerAnim;
    7.             AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(3);
    8.             // Rebind then resetinfo
    9.             anim.Rebind();
    10.             anim.Play(info.shortNameHash, 3, info.normalizedTime);
    11.         }
    12.  
     
  4. castor

    castor

    Joined:
    Sep 9, 2012
    Posts:
    40
    I tried it, but I get a T-pose for a single frame. Is there a way for that not to happen?