How to use ForEachLoop to remove items from array?

Hello! For example of problem I created a simple Blueprint - I’m adding some elements to empty Cell_Array and then try to remove them all. But 1/2 of elements are still in Cell_Array after all. How to remove elements from Cell_Array while iteration using only blueprint scripting? What is the usual solution?
Thanks!

1 Like

The problem is that as you remove items from the array, it shrinks some elements passed below your current index. You can create a ForLoop to go in reverse manually.

Hope that Helps =)

1 Like

Here is the Macro code to create your own “ForEachLoopReversed” =)

1 Like

Copy the array, now you have 2 identical arrays. Do foreach loop on either array and remove the coresponding index from the another array. Should work.

Great Job!

For those stumbling upon this, note that there is now a Reverse For Loop already implemented for you. Joy!

4 Likes