For Each Loop only working at random!

So as i’m trying to build a basic fighting system i came across this pretty random issue.
It’s set up so that the player character has a box collider (DamageBox) and when i press attack an animation is started and an anim notify calls the attached PerformAttack Event. (The boxes have an Any Damage event which should destroy them every time i hit)

you can pretty much ignore the booleans, nothings wrong there, it also doesn’t make a difference if i apply a class filter in the overlapping actors.

as debug function overlapping these boxes makes them red while ending the overlap makes them white/pink.

if it were only the boxes at the outer edges of this collision box that are not affected by the for-loop everything would be fine, i could just make the box bigger, but even objects entirely inside the box are ignored at random which is pretty bad.
Attached files are the blueprint, the stack of enemy boxes once i overlapped them with my DamageBox without hitting, then after 2 hits and one from the player perspective.

I’m grateful for any info you can give me!

I think the problem is in cooperation of the hit animation and the ForEach loop, the animation in still playing while the loop performs and at every given point in time overlapped components change.
You shouldn’t use ForEach loop here. You should apply damage On Begin Overlap same as you make the boxes red.

Why ForEach? Maybe there’s something I can’t see though.

hm yeah i might try not having the box on all the time but only switch it on instead. Then i can just use the Begin Overlap event once every time i hit. Thanks!!

i guess it could be an issue if the array of overlapping actors is cleared and refilled every frame. since the player actor and the attached box are not moving in any direction (root motion is disabled) there shouldn’t be a change in the overlapping actors.

you see what i’m trying here is to have this DamageBox on all the time and use Apply Damage to everything inside that Box once every time i attack. Thus the for each loop over all overlapping objects of this box.
Maybe i could make this work (just for the sake of testing this^^) if i save the array of overlapping actors to a variable and loop over that variable instead of the ever changing array of overlapping actors

So thanks to Tuerer i thought again on the way “Get Overlapping Actors” works. I believe that the array is being cleared and recreated every frame, so the “For Each Loop” ends randomly since the array is being cleared before it can reach the end.
So the function can never really iterate over every object before the array is emptied again unless enough objects have been destroyed that the array is short enough to be iterated over in under one frame.

It is probably much smarter to just activate and deactivate the triggerbox instead of having it on all the time and iterate over everything inside once every attack.
Though for the sake of resolving the error and proving that i’m not completely insane i fixed my original BP by saving the Overlapping Actors in a Variable before attempting to loop over the array.