#unreal#gotchas

If you wire a Blueprint Pure Node into a Blueprint Foreach Node, there is a big danger of bugs. If any node within the loop body affects the result of the pure node (such as deleting items from an array), the foreach doesn’t loop through everything because the pure node gets called again on every iteration.

Solutions:

  1. Store the value from the pure node in a variable, and connect the variable into the loop instead.
  2. A Blueprint Reverse Foreach Node can be used in situations where the array is known to be mutated from the start. Need to be careful when using it though, so option 1 is probably a better choice.
  3. Depending on the case, it might be better to just give a C++ function to perform the task instead. This will never happen in C++ code, and the loop will likely be more efficient as well.