Manually updating animator incorrectly fires animation events!

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

BUMP!!!

Why would you Update(Time.time)? The argument to Update is deltaTime - how many seconds you want to mvoe the animator forwards. That’s going to be a large number if you use Time.time, so you’re going to be looping through your animation very many times, which is what’s going to cause the events to be fired.

Check the docs.

That isn’t correct. DeltaTime skips a frame when used here. Whenever I used Time.time, the animation would start exactly where it should. :slight_smile: