Animation events fire off when animation restarts

I’m working on a project where I’ve been hired to add audio and some particle effects. To add particle effects to animations, I’ve added a few animation events. This is working well. However, there is an issue where after the first time an animation has played, every time after that, at the start of the animation all the events seem to fire at once, then when the animation plays they fire as normal.

So for example, I have a “Throw Money” animation with 16 events. The first time it plays, the money particle is spawned 16 times during the course of the animation. When I try playing the animation again, 16 money particles immediately spawn - and then as the animation plays out another 16 spawn over the course of the animation.

It seems like Unity is “rewinding” the animation during a single frame, or something similar. Does anyone know what might be causing this?

If you're using the Playables API, you just need to call SetTime twice to avoid triggering events (and root motion).

I've never seen that behaviour outside of the Playables API.

I was able to solve this by looping through all the AnimationStates of the animation, and checking the weight of each specific animation using their name. It's not perfect, but it works well enough.

1 Like

Since this is solved I'll lock it now :)! Let me know if youd like me to reopen it if you need further help.