- Home /
Why do animation events have occasional delays?
I am currently working on a fighting game in which our hero can perform various attacks like a punch or a kick.
The damage from these attacks needs to be dealt to enemies on specific frames of the corresponding animation rather than at its start. So I've been using Animation Events to trigger the damage. This is incredibly convenient from a designer's standpoint.
But my problem is that there is an occasional delay between the correct animation frame being shown and the damage actually being received by the enemy. For example I can see the hero's fist being fully extended, and yet the enemy will not take damage until much later. The delay can be up to 250 ms, which is unacceptably long, and yet sometimes it will be 30ms or less, which is perfectly fine and not even noticeable.
So as someone who is fairly new to Unity, my question to you is this: Does anyone know why this delay might be occurring? I haven't seemed to be able to fix it even by deploying a release build. Any pointers much appreciated!
The Event calls a function which does various things in code, yes, but it was created and placed "normally" using the Animation view... why?
Did you ever manage to solve this issue? I have the same issue I am afraid! :(
Answer by smoggach · Aug 11, 2014 at 06:51 PM
The delay is probably occurring due to the code your event is causing to run. You should ask your programmer about it. I'm going to guess it's because it's spending that 30ms - 250ms decompressing and/or loading the sound into memory.
I am the programmer :). There's no sound being played (yet), it's just a straight boxcast to check for damage dealt.
Have you tried ti$$anonymous$$g how long your boxcast is taking? Perhaps there is something in your scene causing it to take extra time in certain situations. In any case it's probably a good idea to replace all code with a debug output ins$$anonymous$$d and see if the issue persists.
Also I've had some weird issues crop up due to animator states.
Your answer
![](https://koobas.hobune.stream/wayback/20220613160058im_/https://answers.unity.com/themes/thub/images/avi.jpg)