Hi there
I have some behavior that I find is a little weird. I have a collider wich represents an explosion. The first tick that the collider is active I use GetOverlappingActors to get any targets hit. I then use a for each loop, to iterate over the targets and deal damage .My problem is that if a target dies (and is destroyed) the array is changed (the destroyed element removed), but the iterator is the same. Which means that if all targets should be destroyed, effectively only half of them are affected.
Personally I think this is a really dangerous design. But right now I’m just looking a for a proper solution. I can see several fixes, but I don’t like any of them for various reasons.
-
Add a delay before destroying the actor. While this will probably work in most cases, I don’t like it conceptually as I feel it could introduce race conditions.
-
Instead of destroying actors right away, mark them for destrouction and destroy them on the next tick. This might work, depending on how the engine executes tick events (if it is sequential execution). But I feel it adds unnecessary complexity.
Any suggestions? Either a loop solution that avoids the problem, or a better workaround.