Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Animator.CrossFade interrupts the next animation

Discussion in 'Animation' started by Pietrofonix, Apr 3, 2022.

  1. Pietrofonix


    Aug 1, 2020
    Hi guys i have a problem with Animator.CrossFade. Basically i want to change animations with a smooth transition. I initially tried with the booleans, but it started to become a bit messy just with a few animations. Searching online i discovered animator.CrossFade that makes smooth transitions without linking the states in the animator controller. I tried it and i'm having some problems. If i put 0f as transition duration, the animation starts immediately like animator.Play and i don't want this; so i put 0.25f, but in this case the next state is interrupted at the beginning after about a second. This happens only from idle to walk, instead from idle to crouch with 0.25f, the animation plays correctly (very slowly but it ends). I leave a code example:
    Code (CSharp):
    1. override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    2. {
    3.         if (m_playerController.IsMovementPressed)
    4.         {
    5.             animator.CrossFade("RifleWalk", 0.25f);
    6.         }
    7. }