Animation event not triggering

Currently in my game a lot of events are triggered from within an animation and occasionally they seem to be skipped over. It’s imperative that an event never get skipped, how do I make sure this doesn’t happen?
Here are the settings on all my animations:
Example of how events are placed:

1 Like

How much searching did you do before posting?

One of many threads asking the same question you are asking.

The answers on a lot of the threads I’ve gone through are quite old, I was hoping there was updated information. Furthermore they aren’t actually “answers” more like “this is broken don’t use it” so I was hoping to find an actual answer.

26 Likes

@Happy_Jingle

I feel you man.

I might be able to help you, not sure if it’s the same issue.

I had trouble when I tried to call an event on a frame, and that frame was occuring during a transition to another animation.

Like If I was punching, and mid animation I would kick, the last frame wouldn’t call the event.

Could it be your issue too?

To resolve this issue, I’m using a way that might not be the best, but it works for me.

I have both event on the animator and state machine behavior with the same event call on the OnStateExit fonction.

Why both?

Event : Sometime won’t call on transition.

State Machine Behavior : Won’t call OnStateExit if the animation loop, and it was looping for me. If you aren’t looping, you can only use State Machine Behavior.

I hope it helps you!

4 Likes

Please log a bug if there is something that doesn’t work as expected.
We do have over 50 different test for animation events that are run everytime we do build unity that cover many edge case.

If there is some case that still doesn’t work we would like to know

1 Like

Does the situation I describe is a bug? I just thought it was how it was supose to work?

If you expect that your animation events should be fired but it not fired then yes log a bug, we will do the investigation and if we found out that it broken we gonna fix it, if it not broken we will give you an explanation why we think it work as expected.

So yes log a bug

2 Likes

Where is the documentation for animation events with mecanim? I can only seem to find the docs for animation events when using the legacy system. For example, how does events work during a transition? Some googling seems to suggest they’re broken with mecanim, but those are mostly old posts.

1 Like

There is nothing specific to mecanim or legacy, basically if a clip is currently playing it should trigger events.

A transition is essentially a cross fade between 2 animation clip, so as long as both clip are played they should both trigger animation events.

There is no know issue with animation events at the moment in 2017.1 and on newer version so I would expect them to work reliably

1 Like

Last frames on animations are definently skipped at times. Especially during a transition to another anim. Giving me headaches

4 Likes

Any news about how to solve this?
For me it is impossible to use animation events because sometimes they work and sometimes they do not.
I just want to send a message to another script when the animation reaches a certain frame but it does not work exactly. It’s a simple trigger animation.

1 Like

Please log a bug, there is currently no know issue about animation events not firing for the animator component

I ran into this problem of an event not reliably firing which was at the very end of an animation. After reading the suggestion from the link posted above (https://answers.unity.com/questions/806949/animation-events-not-firing.html?_ga=1.173591524.614614035.1460979856) I removed the default blends from the Animator state machine i.e. set exit time to 1.0, transition duration to 0.0 and it seems to fire reliably now.

5 Likes

Hello I am having the same problem. I will introduce my case:
I am using Animation Events to trigger sounds at a specific frame. For some reasons the events placed at the first key frame are only triggered the first time I play the animation. The next times I try to play the animation the Animation Event is skipped. I am using Simple Animation Component to trigger the animations not Mecanim. (So we are not using transition blending or exit time)
https://blogs.unity3d.com/es/2017/11/28/introducing-the-simple-animation-component/
In theory uses Playables to play the animations.
My unity version is 2017.3.1f1

Any help will be very usefull

Regards


3459606--274351--PrtScr capture_3.jpg

1 Like

Hi i’ve worked on three different projects with Unity and i’ve always had problems with animation events at the end of animation because they seem to fire whenever they want to, to solve this i’ve come up with two methods:

1: Put a phantom frame at the end of the animation, after the event frame, and example of phantom frame is a GameObject property which will be enabled/disabled according to your current animation so it won’t change anything.

2: Get the animation length which you desire to activate the event and at the end of the desired animation activate the event.

Obs: I’ve never used state machine behaviours, so it might be a good alternative.

1 Like

If Blend Animation causes Animation Event unreliable, then I have to drop Animation Event method. I can use StateMachineBehaviour & Animator.GetCurrentAnimatorStateInfo.normalizedTime to handle the event myself for this case (cause I can’t drop Blend Animation for this case)

I’m having this problem as well. I’m using Animation Events to tell my Behavior Designer tree when an animation has finished playing (the animation event fires on the last frame of the animation). In the tree, it just waits forever until it gets the message that the animation has finished. It works most of the time, but sometimes I would find an enemy who is in the next crossfaded animation state but whose behavior tree is still waiting for the animation end event-fired message for the previous animation.

Nathan’s workaround sounds like a right pain in the ass. I have a lot of events besides the end of animation event so any news on a permanent fix for this would be appreciated.

EDIT: Just to be clear, the animations I’m putting the animation end event on are not looping. I’ve tried other solutions for telling when an animation has ended but those had problems as well.

1 Like

It’s been a while since I had to use Mecanim, but could it be that the transition is starting before the end of the animation and timed to finish at the end of the animation? In that case, floating point error between the keyframe/event and the system that determines which states are playing could be causing the state to stop before it actually evaluates the last frame. That would explain why it only happens some of the time since it would be precision errors accumulated from the varying delta time.

I had the same issue…but I fixed it. I had an trigger at the end of the animation frame and it was firing based on debugging but my code was not handing my characters different action properly. For example, I had the trigger call a function when the animation ended to indicate the attack was done so the AI could do something else…like attack again. To make a long story short, I believe it may have been continuing an animation before it actually stopped and maybe starting again? Not sure but when I started the animation specifically starting at frame 0, it works fine:

anim.Play( “attack”, -1, 0);

I hope this helps!

1 Like

Tried it on unity 5.5.6 and the last frame with trigger event is still skipping.