Animation events are still executing after transitions

Hey folks, I’m trying to add in flinching to my project. For example, you do a slow attack and an enemy does a fast attack. The fast attack hits you and cancels your slow attack.

However, I can’t seem to get the transitions right. Currently I’m testing by automatically cancelling an attack as soon as it happens. I have a transition back to the idle state, ‘Has exit time’ false, so it should automatically go back to the idle state. However, the animation event is still executing the onAttackHit functions.

This would mean that even if I cancel the animation properly, it will still do damage, even if the animation never showed your character hitting.

What am I missing?

What’s the transition time set to for the transition back to the idle state? Depending on how quickly it happens and how quick the attack animation is, there might still be some overlap. You can try to set the transition time to something very short like 0.01, but this might give you a very abrupt transition. One way to handle this would be to set a bool in your attacking script that is set to true when the attack animation begins but can be set back to false if the attack is interrupted. Then, have the onAttackHit function check to see that the attacking bool is true before executing it’s code.