Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Animator.crossfade causes animations to stuck (sometimes)

Discussion in 'Animation' started by matreusz4, Apr 20, 2022.

  1. matreusz4

    matreusz4

    Joined:
    Jan 18, 2020
    Posts:
    13
    In my game I have really big amount of animations and I need possibility to transit between them smoothly so I'm using animator.crossfade to play animations.

    That short video shows what im talking about:

    On the video, it happend twice. Transitions beetwen animations were unnaturally slow, like in slow motion. And when it happends, on the animator tab, it shows, that animations that should just end are stuck for a fraction of a second.

    My function to play animations is very simple. Something like that:

    if (currentAnimState == newState)
    return;
    else
    animator.CrossFade(newState, transitionTime, 0, 0, 0);

    And the transitionTime depends on how quickly I want to change to a given animation. I never change the rest of the parameters ( normalizedTimeOffset and normalizedTransitionTime) because im not sure how it works.

    This little problem leads to a bigger problem - sometimes the whole new animation will not load because the previous one has not finished its transition, or it loads incorrectly. I need instant animations always animated at the same speed.

    Please, help needed
     
    Last edited: Apr 20, 2022
  2. matreusz4

    matreusz4

    Joined:
    Jan 18, 2020
    Posts:
    13
    Using animator.crossfadefixedtime instead of crossfade looks like it's solving the problem partly (it looks like now its very rare)
     
    Last edited: Apr 20, 2022
  3. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    I've experienced this too in the past, I think it's the non looping animations that cause this if we don't exit the anim before they end.

    Just a thought, maybe adding a well-placed exit transition to all non looping anims could prevent this? Or reviewing your cross-fade timing.
     
    Last edited: Oct 2, 2022