Search Unity

Question Animation State and Animation is not synchronized

Discussion in 'Animation' started by hd-dev1, Dec 25, 2021.

  1. hd-dev1

    hd-dev1

    Joined:
    Jul 7, 2021
    Posts:
    2
    I am new to unity. I have made a custom animation applying animation rigging in it. To make animation I used 'Timeline'. The length of the animation is around 9 second.

    My plan is to rotate the avatar by certain amount of angle with respect to y-axis (yaw rotation) after it completes a single motion (full length of the animation). And this continues for a long time such as (1 hour). For that I have done this as follow in side void Update() :
    Code (CSharp):
    1.         if(anim.GetCurrentAnimatorStateInfo(0).IsName("animation_state") && anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f)
    2.         {  
    3.  
    4.  
    5.             ChangeAngle(); // calling function to rotate the avatar
    6.  
    7.             anim.Play("animation_state",-1,0.0f);
    8.  
    9.         }

    But the problem is animation and animation state is not synchronized. I mean sometimes animation (9 sec long) is finished but animator state is showing that it is not finished and not changing the avatar rotation. It changes the avatar at the middle of the animation. But I want the avatar will only rotate when the single animation is finished. Initially it runs fine, this problem occurs after completing 5/6 min. For example:
    upload_2021-12-26_1-12-45.png

    Animation finishes but in state diagram progress bar it says it will require few more seconds to finish. How to solve this?