Search Unity

Bug The animation events do not scale with animation speed Unity 2021.1?

Discussion in 'Animation' started by Sangemdoko, Feb 11, 2022.

  1. Sangemdoko

    Sangemdoko

    Joined:
    Dec 15, 2013
    Posts:
    222
    Hi,

    I'm having an issue with animation events, and I believe the problem has to do with animation event timings not scaling with the animation speed.

    I have an animation with 6 frames. I fire two events at around 20% and 90% of the clip.

    I added state machine behavior to my animation state to log some things:

    Code (CSharp):
    1. public class TestAnimBehavior : StateMachineBehaviour
    2. {
    3.     // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    4.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    5.     {
    6.         Debug.Log(Time.frameCount+" ENTER FIRE ANIM STATE "+stateInfo.normalizedTime);
    7.     }
    8.     // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    9.     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    10.     {
    11.         Debug.Log(Time.frameCount+" UPDATE FIRE ANIM STATE "+stateInfo.normalizedTime);
    12.     }
    13.     // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    14.     override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    15.     {
    16.         Debug.Log(Time.frameCount+" EXIT FIRE ANIM STATE "+stateInfo.normalizedTime);  
    17.     }
    18.     // OnStateMove is called right after Animator.OnAnimatorMove()
    19.     //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    20.     //{
    21.     //    // Implement code that processes and affects root motion
    22.     //}
    23.     // OnStateIK is called right after Animator.OnAnimatorIK()
    24.     //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    25.     //{
    26.     //    // Implement code that sets up animation IK (inverse kinematics)
    27.     //}
    28. }
    I would expect the events to fire around stateInfo.normalizedTime 0.2 and 0.9 no matter the animation speed.
    But instead it gets fired at 0.2, 0.9 when speed is 1 and around 0,0001034698 and 0,0005153804 when using a speed of 0.001.


    Does anyone know if that's a known bug? Or if I'm actually doing something wrong?