Get overlapping actors not getting all the actors in a box despite them being identical (UE4.27)

This not really a good solution. You need to understand pure nodes:
“Get Overlapping Actors” is a pure node (no execution pins), every pure node will be called every time it is accessed, in this case every loop!. So in this example, let’s say there are 4 Actors in the sphere, if you run the code with a normal loop, the following happens:

    1. Loop Call → Get Overlapping Actors → Found 4 Actors → Actors[0] → Destroy (works)
    1. Loop Call → Get Overlapping Actors → Found 3 Actors → Actors[1] → Destroy (works, but the first one was skipped)
    1. Loop Call → Get Overlapping Actors → Found 2 Actors → Actors[2] → Destroy (does NOT work, since index 2 is not valid anymore)
    1. Loop Call → Get Overlapping Actors → Found 1 Actors → Actors[3] → Destroy (does NOT work, since index 3 is not valid anymore)

if you run the code with a reverse loop, the following happens:

    1. Loop Call → Get Overlapping Actors → Found 4 Actors → Actors[3] → Destroy (works)
    1. Loop Call → Get Overlapping Actors → Found 3 Actors → Actors[2] → Destroy (works)
    1. Loop Call → Get Overlapping Actors → Found 2 Actors → Actors[1] → Destroy (works)
    1. Loop Call → Get Overlapping Actors → Found 1 Actors → Actors[0] → Destroy (works)

The better solution is very simple, save the result from “Get Overlapping Actors” to a variable and loop the variable. The “Get Overlapping Actors” will be run only once now (to set the variable) and the array in the varialbe will not be changed when you destroy actors.

So this code will run like this:

  • Get Overlapping Actors → Found 4 Actors → save as “Actors”
    1. Loop Call → Actors[0] → Destroy
    1. Loop Call → Actors[1] → Destroy
    1. Loop Call → Actors[2] → Destroy
    1. Loop Call → Actors[3] → Destroy
1 Like