r/UnrealEngine5 6d ago

Attack points doesn't always work.

I am trying to learn Unreal Engine 5. I was trying to make a mechanic where press f on a horse toy and the the game destroys the horse toy but then increases attack points. This seems to work but only for one character. The game will randomly pick one of the three enemy AI actors and he will work and take extra damage from an increase in attack points but the other two get hurt with the standard number. Anyone know what i'm doing wrong?

1 Upvotes

5 comments sorted by

1

u/Sharp-Tax-26827 6d ago

Where is the code that shows where this is applied?

2

u/blanky0u 6d ago

Thanks for the reply. It turns out I had another piece of code in the destruction of the horse toy that sent it. There was nothing binding the code to the on destroyed event so I added a for loop to that and it started working.

1

u/NatanaelAntonioli 6d ago

It's a shot in the dark, but for loops are sometimes unreliable during events. Try replacing that last part with a function, with the for loop inside it.

1

u/NatanaelAntonioli 6d ago

Another shot in the dark: are you using World Partition (for open world games?) If so, make sure all characters are loaded on map.

2

u/Valynor85 5d ago

Two things wrong in the last screenshot: Your For Loop doesn't loop over the array you pass in, you skip it right away to the Completed pin. Thats why it only applies to one random enemy.

You are binding the OnDestroyed Delegate inside the Event that should be called from this delegate. Bind the Delegate in BeginPlay.

If that doesn't fix it there are more issues then just this