- Home /
Why is mecanim Animation Event not Firing when on last frame?
This is one of my biggest frustrations with Mecanim. If you place an animation event on the last frame of an animation it seems as though there is no guarantee that it will be called. I have set the Exit time to 1 and the transition duration to 0 in order to mitigate the issue of the transition interfering with the event but I still have the issue.
I have attached a screen shot of the animation with the event and the transition info. If anyone can tell me what I am doing wrong it would be much appreciated.
I recently discovered State$$anonymous$$achineBehavior specifically OnStateExit which seems to be a reliable way to watch for the end of an animation state.
http://docs.unity3d.com/ScriptReference/State$$anonymous$$achineBehaviour.OnStateExit.html
Please post any solution you find or an explanation to why/how to get the last keyframe animation event to work I would really like to understand...
Since it seems like animation events are skipped when frames are skipped and everyone dislikes this, please take the time to vote on this suggestion to add a feature which will allow us to choose to make our animation events guaranteed:
https://feedback.unity3d.com/suggestions/animation-event-guarantee
Answer by AtticusMarkane · Nov 06, 2015 at 04:41 PM
So I discovered what I was doing wrong.
When using an event on the last frame two things need to be done:
Make sure that your transition in Mecanim does not occur until the entire animation has finished playing
Make sure your animation does not have "loop time" enabled. This appears to occasionally skip the final frame.
Do these two things and you should be in business!
This used to work.
However, at least as of version 5.4.2f2, I'm finding that this solution no longer works.
Animations Events that I had set up to rely on this have stopped working after upgrading from version 5.3.5p1.
If anyone knows if there's any patches I should look into or if there was any documentation posted about a good reason for this change, please let me know.
Thank you.
I haven't noticed any issue with this but to be fare I have not been doing a lot of $$anonymous$$ecanim work lately. I'm not sure if it helps but have you tried looking into the State$$anonymous$$achineBehaviour class? https://docs.unity3d.com/ScriptReference/State$$anonymous$$achineBehaviour.html
It allows you to monitor for changes in the $$anonymous$$ecanim state machine and run code based on them. Its not exactly a fix, but it may help you do what you are trying to do now.
Apparently it's a bug in the latest version. I found an issue here: 843714
I'm trying to figure out if there's any patched versions that fix this. I haven't been able to find one yet.
I noticed this issue as well and I just "solved" it by putting the Event one frame before the last one.
Your answer
Follow this Question
Related Questions
Will Mecanim make the Locomotion System obsolete in Unity 4? 2 Answers
How Complex Should Mecanim State Machines Be? 2 Answers
3ds 2013 biped with horselink (4th leglink) compatible with mecanim? 0 Answers
Mecanim Networking 0 Answers
Delay and Twitching when using an empty state as Transition between multiple other states 0 Answers