For some reason I’m dealing damage multiple times per attack. I’ve tried a “do once” node, but maybe I’m not suing it right.
When/where are you running the ‘Hit Enemy Character’ function? Maybe you are firing it more than once.
Are you using multiplayer while you are testing this? Do a print string after the ‘Hit Enemy Character’ on the BP above and see if it prints twice.
Yea its hitting multiple times. Its somewhat random how many times it hits though. As little as 1 (rarely) and up to 10 or so. Thanks for helping out. I’m sure this stuff is obvious, I’m just super new at it.
It looks like its calling for every tick that the sword is touching something.
It shouldn’t, does it hit the same amount of times each time you test, or is it seemingly random?
Its consistently printing 3 times when I swing the sword at the grass, but random when I hit the enemy. It almost seems like its colliding with his mesh and dealing damage each time it hits an arm or something, rather than dealing damage once per swing.
Promote the “Actors to Ignore” slot from the capsule check into a variable and, after dealing the damage to the actor, add the hit actor to that array. Clear the array after the swing. This will prevent the capsule check from hitting the same actor twice, since that actor is now added to the “ignore list”.
I haven’t really worked with arrays so I’m sure I’m setting it up wrong, but this isn’t working. I know I haven’t cleared it yet, just trying to get it to stop hitting more than once.
Actually its kind of working now. Fiddling with it. I will let you know if I can get it working.
Since the hit will register multiple times, I would put a Branch after the hit to verify if it is hitting something new.
do you want to be able to damage multiple enemies at once? if not it could be easily solved with a do once node that resets after the swing has been done.
Your problem is that on each tick you are checking if the capsule is hitting something, but you are not checking if actor X has been hit already or not. What you do is create an Actor array and if a hit was landed, you add that actor to the array and at the beginning of the trace, you check if the actor hit is inside your “HitActors” array with the function “Contains”. If it contains the actor, you just don’t do anything, if it doesn’t contain it, you proceed to damage the enemy. At the end of the trace you clean the HitActors array and back again.
This is because you are targeting the hit actor from the Event node rather then the hit actor from the Trace node. The Event node will return the actor regardless of what’s in the “ignore” array while the Trace node will not return the actor if it is in the array.
However, you can add a branch immediately after the Event node and check the array for the hit actor. This will allow you to remove the Trace node entirely, since you are already checking for collision from the Capsule Overlap event.
Recreated exactly what you did, but now I’m not dealing any damage because its constantly reading that I already hit the enemy. Its never reading the hit enemy character event. I tried adding in a “clear array” node after the attack animation stops playing, but its not event getting though to do that. Do I need to have a clear array on event begin play or something?
Below is my current blueprint. I left in the capsule trace because I’m using the hit location to spawn a particle effect there at the end of the the “Hit enemy character” function. The first image is in my “item weapon” blueprint, and the second is in my character blueprint.
UPDATE:
It now will hit the enemy randomly. It seems like its only dealing damage once per swing (which is progress), but its not damaging every swing.
Or could I remove the trace node and run “sweep result” off of my overlap event to “break hit result” node to get the location for spawning the particle effect on hit? Sorry, I know thats a bit off topic.
Clear the array before starting the attack rather than during.
The way you have it now will only clear the array IF the target has already been hit AND if the animation has stopped. This means that if the animation stops when no actors are being overlapped, then the array will not clear.
I added clear directly after event begin overlap and now I’m back to the old problem of multiple damages per swing. I tried to add in the “input action attack” node to clear on the beginning of that, but for some reason its not calling at all. Perhaps because I’m in the weapon blueprint instead of the character blueprint?
Ok so I added the clear array in to my character bp, under the input action attack, and the damage is much more consistent now. Every 3 or four swings it will deal damage twice.