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!
asked Nov 28 '18 at 05:42 PM in Blueprint Scripting
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here