- Home /
AnimationEvent triggered multiple times?
no matter what set of checks I perform on an AnimationEvent that was created on an AnimClip during the "Start" method in a class, I'm getting the method the event calls being triggered multiple times, usually 3-4 times(oddly enough). I've done numerous debug.log checks to test as to how many times the method that triggers the animationClip that houses the AnimationEvent is being called, and it only show that this initial method calling the animClip that houses the animEvent is being called once, yet the debug calls that the method that the AnimationEvent triggers are reporting themselves being called 3-4 times in a single animationEvent call. Has anyone run into this issue for found a fix? Pardon my not posting code, again though I'm simply playing an AnimClip from a method in another class, ONCE, thats it, and I continuously get the debug logs showing the event's method is being called multiple times, yet the event that is triggering the AnimClip with the event is only reporting being called once ??? Thanks for any help :-).
Is this a matter of making the animEvent placed in a "tighter" float position, say as opposed to "0.9f", going with "0.9999999999f". I'm wondering if this event is being called multiple times due to a random lag in gameplay that could occur around the "0.9f" point in the animClip?
Answer by 3Duaun · Sep 28, 2011 at 04:16 PM
No need to "thumbs up" this answer, I just want to archive it for the community. It appears that, in our case, we're using a PoolManager of sorts for "enemies" in a title we're currently developing. The "Start" method activates on EACH of the SAME enemies that are being pre-pooled(mostly for mobile performance), the same additions of the same animationEvent to the SAME ANIMATION CLIP somehow, as if they're all sharing the same animation clip amongst the multitude of individually instantiated enemies of that type. So for future reference, do a check for a pre-existing event of that name(perhaps at that time), and dont add it again if it already exists; just a heads up in case anyone else runs into this issue.
just found this answer that wasnt showing up at all before?? http://answers.unity3d.com/questions/125193/enemies-spawn-with-multiple-of-the-same-animation.html
Yep, i also had to learn this the hard way :D, but it all makes sense once you get it. Animation-Events are "usually" added in the animation window where you edit your Animation-clip. This clip can be shared between many objects. However imported animations (almost) can't be edited so you need to add the events via script.
I recommend to add the events in some kind of manager-script that exists only once in the scene. This manager class only needs the AnimationClip references.
Another way is to use an editor script to "clone" / "copy" the animation and save it as true, seperate .anim file. This one can be edited in the animation window. The problem with this method is that you can't really update the AnimationClip since it's a copy.
Thanks a lot, I suppose you just saved me a lot of time! :)
Your answer
Follow this Question
Related Questions
How to prevent an animation from triggering more than on due to fast clicking? 2 Answers
AnimationEvent not reliably triggerd on iPhone 1 Answer
AnimationCurve for ScriptableObject 0 Answers
Animation events won't trigger if animation time set manually 1 Answer
StateMachineBehaviour is working weird with AnimationClip.AddEvent 0 Answers