Search Unity

Question Animation events fire off when animation restarts

Discussion in 'Animation' started by LandePlage, Aug 31, 2021.

Thread Status:
Not open for further replies.
  1. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    33
    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?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    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.
     
  3. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    33
    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.
     
    KalOBrien likes this.
  4. KalOBrien

    KalOBrien

    Administrator

    Joined:
    Apr 20, 2021
    Posts:
    89
    Since this is solved I'll lock it now :)! Let me know if youd like me to reopen it if you need further help.
     
Thread Status:
Not open for further replies.