Identifying two items (with same world transform) and removing both from Array

Hi :slight_smile:
I have an array with arrows that I use to spawn walls. If two arrows share the same worldtransorfm, no wall shall be spawned, thus I need to remove both arrows from the Array.
I started by doing a for loop and removing the current item from the Array, then do another for loop inside the body of the first to iterate the Array -current item. I learned that this was not possible as modifying an array while iterating it leads to problems. So I made a copy of the array and removed the current item from it to use it in the second loop. In the second loop I look for a world transform match and if it is true, I remove the next item from the copy of the Array. But here I again modify an Array while iterating it and thus this is not a working solution.

So any suggestions how to remove two items with a common attribute from an Array?

Here’s where I’m at:

I managed to find a solution that should in theory work, but only works sometimes and I am unable to figure out why.

Instead of removing the second match, I create a new Array and add both matches (Arrows To Remove Array). Once the outer loop is complete (when all arrows were compared to all array items and the temp exits array is empty), I reset temp exits to the intial exits array and loop through the findings (Arrows To Remove Array). For each entry in Arrows To Remove Array, I again loop through Temp Exits and look for matches. Those matches I then remove from the initial Exits Array.

The problem seems to be, that not all matches get added to the Arrows To Remove Array in the Upper Condition Branch. I found that it finds only about a quarter of the matches it should find.

I will keep trying to figure this out, but am pretty lost right now.

Here’s the screenshot:

I have now replaced the two for loops on the top with reverse for loops and get better results, but still a lot of matches are missing from my result, so something still is off. Any help is appreciated :slight_smile:

I found the problem and it has nothing to do with the area in this ticket but stems from the general setup. I think the loops work as they should.

Edit: The loops as seen in Screenshot 2 work like they should. Screenshot 1 was still a mess :smiley:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.