I’ve done some research on this issue, but have so far been unable to find a fix, so I decided it was time to come here.
TL;DR: I’m using a collision mesh with an overlap event to cause damage. I’m using a retriggerable delay function to count only one hit. But the one hit is only very rarely being passed to the hit actor. Aka, the AnyDamage node never fires, even though damage is being dealt.
The Setup: I have two character type blueprints: a player and a troll. Every tick, the Troll checks to see if it is in a hardcoded attack range to the player. If it is, it plays an attack anim montage. The troll has a collision mesh around his hand, and the anim montage makes him swipe this hand in the direction he is facing. This code executes perfectly.
The collision mesh around the troll’s hand has a Begin Overlap event. After some branches, damage is applied. The Other Actor on the event is hooked to the Damaged Actor on the Apply Damage. Immediately before the Apply Damage function, there is a retriggerable delay function. This prevents every hit of the troll from being counted (because the collision overlaps like five times a hit), and returns only the first hit. This code executes perfectly.
The player character simply has an Any Damage event, which takes the damage dealt, subtracts it from a Player Health variable, and then sets the Player Health variable to the new amount.
The Problem: The Any Damage event ALMOST never fires.
What I’ve tried: First off, I’ve looked at several other questions where this same problem occurred. One answer suggested setting the collision (it didn’t specify WHICH collision) to Pawn. ALL my collisions are now set to pawn. No difference. I also double checked that everything can generate overlap events.
I have tried extensively to debug this. As you’ll see in the screenshots below, I have Print Screen functions which tell me 1) what actor the troll is hitting, 2) if the troll is applying damage, and 3) if the character is being damaged.
The first two strings print fine. They confirm that the troll is indeed damaging the player character, and that he is indeed dealing damage. The third print string fires only very occasionally.
My Confused Thoughts: Obviously, this alone makes no sense. The troll IS damaging the player, but the player is receiving no damage. But there’s more:
I have two attack anim montages I can use for the troll. One is a simple swipe (the one I’m using). The other has a bit more wind up, and he steps forward when he swipes. This second montage has a better chance of damaging the player than the first. Due to the retriggerable delay function, the troll is still only hitting the player once, still only applying damage once. There should be no difference. But there is.
There is one final piece: If I (as the player character) stand still and let the troll whack me repeatedly, after one of two swings he starts doing damage (and I start receiving it) reliably. But if I move, I stop being damaged - but the troll’s strings STILL SAY I am being damaged.
My Question: So here’s my question: how can the troll’s code say he’s damaging the player, and the player say he’s receiving no damage? And why does the player sometimes receive damage anyway?
Here are screenshots of my relevant code (some are a bit messy with all the strings, sorry about that):
This is the relevant part of the troll’s BP. When the collision overlaps, it checks to make sure he is attacking, then checks to make sure he hasn’t overlapped himself. Then there’s a retriggerable delay (to deal with multiple hits), then he applies damage. This code works fine every time.
This is the relevant part of the player BP. I’ve already explained exactly what this does above, so I won’t do it again.
These are the string returns in-game. This is from two swipes. The first swipe registered two hits against the player (BP_MyKwang2). It dealt damage once (because of the retriggerable delay). But the player was never damaged. If he were, it would have said KWANG DAAMGED! (yeah misspelled I know - I was going fast). The second hit executes correctly. The player is hit twice, damage is applied once, and this time the character is damaged, and his HP reduced (the 97.0).
If the troll weren’t hitting the player, this would all make sense. But the troll very clearly is hitting the player, and is dealing damage. The player just isn’t always accepting the damage. Does anyone know why?