Apply damage once per actor

Hey,

My characters have multiple collision capsules making up their hitbox, I’m using On Overlap Begin for collision. So every time the weapon swing overlaps a component it runs this function. If i set a boolean in the overlap function and then reset it after the swing completes I can only damage one actor per swing.

How can I damage each actor only once (if the swing overlaps multiple different actors)?
If the answer is using the overlap function to populate a TArray and then apply the damage in another function I’m not sure how that looks.

An array is the correct answer as you guessed, to implement that you likely have some Begin/End attack functions, you could handle it in there

Yeah applying the damage in the End attack function could work, but for slower swings with longer active collision it would be awkward and delayed if the collision happens at the beginning.

This is working currently, if the enemy takes damage it sets the boolean, gets reset by timer afterwards.

I only have one method of dealing damage atm but would this idea work with other damage Instigators and Causers in the future. So certain attacks/damage prevent the character taking successive hits of damage and others don’t?

else if (DamageCauser = FireAoe)
{
Health -= Damage;
}

else if (DamageCauser = PlayerWeapon)
{
Health -= Damage;
IsHit = true;
}

Setting multiple overlaps in the components collision settings might do the trick

Are you talking about collision channels because I’ll definitely be adding more.
If not, could you elaborate on “Setting multiple overlaps”

Setting up collision channels for enemy and player attacks can definitely help organize things, but for multiple overlaps, in the class BP, when selecting the sword mesh component search collision, it’s in the tick boxes below the main channel responses

you can still apply damage on overlap, you just need something else to handle the array,

So on AttackBegin clear array.
OnOverlap get array, check if array contains actor else applydamage and add to array

Ok i getcha, so would that use something like a sweep trace with a larger capsule to detect what is in the path of the swing?

not necessarily, you must have something that begins the attack, for instance to start the montage, at that point you can create/clear the array, then on your OverlapBegin you can get access to that array.

then you can still apply damage exactly at the time of overlap.

there are always multiple ways to achieve a goal though :wink:

Yep my bad, I mistook what you said about getting the array.


Thanks for the help this works now :slight_smile:
The - if (IgnoredActors.Contains(SweepResult.GetActor()))

Does that need to contain anything?

1 Like

no but might be cleaner to use ! and get rid of the else but its not important