My answer for where the bug could be coming from is right in the Hit() event when it Cancel has set the target to null. I noticed that turning up the time between attacks made it more obvious: if I cancelled my attack right before the animation plays, it still tries to call Hit() because we created a target for it, but then set it to null when trying to call TakeDamage(weaponDamage).
Even when we’ve cancelled the attack, the animator blends the transition from whereever we are in Attack to Locomotion, and that often involves the Hit() Animation Event being called.
The solution is to have your first line in Hit() be:
if(target==null) return;
1 Like
I’m not really convinced with this solution to be honest.
Couldn’t race condition still happen even with this fix? Is there any guarantee that the Hit() animation event is atomic?