AnyDamage not firing even though BP is damaged

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.

327609-stringreturn.png

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?

This was the issue. It occurred to me literally while you were typing. The troll was hitting himself DURING the delay, causing the damage to be ignored (because there’s a branch preventing the troll damaging himself). I was able to fix this by setting the target variable immediately after the target is confirmed to not be the troll, and then calling it after the delay. That way, if the troll sets the target to himself, it doesn’t matter. This works now.

I was able to solve this issue.

The problem was that during the delay, the troll was hitting himself with his own collision, thus setting the Other Actor to the troll before the delay could finish. Because I had a branch preventing damage from being dealt if the troll was the Other Actor, the damage was simply dropped.

I was able to fix this by promoting the Other Actor to a variable (thank you ClockworkOcean for the suggestion), and setting it immediately after the branch confirming that the troll has not hit himself. Then, after the delay, I call that variable. This way, if the player is hit, the player is locked in as the target, and if the troll is hit during the delay, it does not affect the target.

This solved the issue.

The moment the overlap occurs, store the ‘other actor’ in a variable ( and pass that variable to the apply damage node ). But the time your apply damage node is called, I’m wondering if the other actor variable is actually valid, because of the delay.

No such luck. I set a variable for the Other Actor first thing after the overlap, and then fed that variable to the apply damage node, but there wasn’t any difference. I also used an Is Valid node to check your theory, and the Not Valid exec never fired. So the actor is always valid. However, the problem is definitely stemming from the retriggerable delay. I found that if I remove it, damage is calculated every time. It’s just that the troll overlaps the player 2-4 times a hit. Which I suppose could be a mechanic, but…

Hi, in the code in your first image above it will apply damage to the last actor that triggered the OnComponentBeginOverlap(LeftArmCollision). So if it overlaps the player and inside the time of the delay overlaps something else, it will apply the damage to that something else and not to the player.

If that is what is causing your issues, then one way to solve it, would be to come up with a different solution than using a delay. For example, keep track of all actors that the troll damaged during an attack (add them to an array) and use that to avoid damaging the same actor several times during an attack (only apply damage if the array does not already contain that actor). Then after the attack, clear the array.