Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice
  2. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

Resolved How to Make Instant Animation Change with No Frames In-Between?

Discussion in 'Animation' started by Koaske, Nov 28, 2021.

  1. Koaske

    Koaske

    Joined:
    Mar 30, 2015
    Posts:
    22
    I'm using Animator.Play() to change the animations of a character (I'm not using any triggers), but it would seem that after the Play() function is called, the old animation (the one used before the call) will still be drawn on the screen for a duration of one more frame before the new animation starts playing.

    Is there any way to make the switch to the new animation instantaneous, with no frames in-between?

    I've tried placing these Play() calls to different places, such as Update, LateUpdate and FixedUpdate, but none of that seems to have fixed the problem.

    Note that I'm not using transitions, as there's no need for blending animations in any way.
     
  2. Oir_the_tentacular

    Oir_the_tentacular

    Joined:
    Nov 26, 2021
    Posts:
    53
    You can use transitions but disable "Has Exit Time" and set "Transition Duration" to 0. This will change between your animations instantly without any blending animation and will also fix the issue of stuttering on the previous animation for a frame before going to the next animation.
     
  3. Koaske

    Koaske

    Joined:
    Mar 30, 2015
    Posts:
    22
    Thanks for your input. I tried your method, but it looks like this didn't really have any effect on the instant changing.

    I realized that the issue was that there was a lot of calculating being done in coroutines that affected which animation state should be played. Since animation updates are executed after coroutines, using Update() using that for the animation calls was too early, and LateUpdate() was too late, as this comes after the animation updates.

    I put the animation update code to end of a coroutine, which made the necessary updates just before the internal animation updates.
     
unityunity