Need help on applying damage

Hi, I am trying to apply damage on a hit of an attack using sphere trace by channel. It will trace the weapon socket from the starting bone till the end bone. I did it inside an anim notify state. But I want to make the damage applies only ONCE, how can i do it?

Thanks in advance

Yup, I have actually tried the 2 solutions before, “do once” and “bool” method but both failed. This is my blueprint. I will be glad if you can point out the things that i m missing.


Hi, @OmKhalasi, instead of using a boolean on the tick event to determine if you took damage, there is a node called “Event Any Damage” which will trigger whenever you take damage in any shape or form. That way you wont be spamming the branch on the tick event until you get damaged plus it the “Event Ant Damage” will only trigger when taking damage so you won’t be spamming anything. Although you might want to keep a variable to ensure that the enemy or the player on takes damage once.

I’m not sure if this will affect anything or not, but I recommend plugin something in for Event Instigator and Damage Causer. I also fill in the Damage Type Class, but I don’t thing any of these really matter unless your using them.

Another thing that might help is instead of using a “Do Once” node you can use a “Get Actor Class” node. Currently your code will only damage one enemy. So if the attack were to hit more than one enemy, it will only damage the first enemy hit and ignore the rest which may no be ideal. So by getting the class of the enemy and using a branch you can apply damage to all enemies within that class and ignore any other objects or actor that might also have been hit that you don’t want taking damage.
Hope this helps! :+1:

2 Likes

@ArcReed3215 But the do once doesn’t work, do u know y?

Besides that, i have actually try use “Event any damage” before using (event tick). When enemy get hit, set isDamaged to true then delay 1s b4 setting back to false). Then when isDamaged is false, damage can be dealt in the anim notify state. But neither works…

If it is possible, i hope you can demonstrate the blueprint flow that added the variable u talked about. I am a little bit dumb when comes to logic. I will be grateful about it.

Hi @user_300324773b09952d1f47f0582363200ffcaa31820cfc09f3603719, thanks for the waiting. Here is a basic setup.

Player Variables:
variable
Player Attack Animation SetUp:


Player Events:


Player Tick + Collision:
Part 1:

Part 2:

Part 3:

Enemy Blueprint:

Results:
One Enemy:


Multiple Enemies:

Hope this helps! :+1:

2 Likes

OMG, thanks a lot for actually making the blueprint. Now I understand it better. Imma try tis out 1st. Wish me luck~

TQ very much for ur effort

1 Like

A good solution to the double-hit trace problem! Thank you very much!

However, I don’t like attaching logic (especially Branch nodes) to the EventTick you showed in PlayerTick+Collision screenshots. Because on EventTick, the Branch is processed every frame(!). Using my technique, you will no longer need AllowTrace boolean and costly EventTick logic.

There is an easy optimization:
instead of EventTick, attach to swordTraceLoop (LoopCollisionTrace for your naming convention) event and pass its delegate to StartCollisionTrace (my swordTraceStart event).

  • my ActorsHitBy1Trace array is the same as your HitActors array
    my swordTraceStart = your StartCollisionTrace
    my swordTraceStop = your EndCollisionTrace
    ** Other graphs are the same as yours

How it works:
when swordTraceStart event is called, Timer starts calling swordTraceLoop with period set by Time parameter. Timer does so until ClearAndInvalidateTimerByHandle is called.