So I have run into an odd bug that I’m not quite sure how to fix. Whenever I change animations for the player character, I use a method that first calls the line anim.Crossfade(“animName”, 0, 0, 0) and then the next line say anim.Update(Time.time).
Now, this seems to work fine at IMMEDIATELY updating the animator to the correct state, but I noticed that with any state that has an animation event in it, when that update line is called, it also immediately fires the animation event(s) of the old state as it goes to the new state. Even though the state is clearly NOT at the correct timestamp when the animation event should fire.
I tried an experiment or two, and if I instead change Time.time to Time.deltaTime, the bug doesn’t occur. But then my animations are off slightly and deltaTime is clearly incorrect here.
Can anyone explain why this is how or how to fix it? I thought maybe it was a glitch because I was using an older version of Unity, but I updated to the newest version and it is still happening.
EDIT: I found this old thread that is possibly related to this issue. Humourosly using anim.Update(0) seems to work fine but not anim.Update(Time.time): Animator.Update(0) firing events in Unity 5.6