Cannot Adjust for the Index shift when Removing from Array During ForLoop
So, I still have the problem that when removing elements one by one from an array (or instanced static mesh component) during a for loop I'm unable to adjust the new index correctly to take in account that the array shrinks each time it has removed an element.
Initially I wanted to solve this problem with a reverse for loop but with this method I noticed that I am unable to update my reference which is imperative for my system to work correctly.
As you can see in the picture above:
As you can see I'm using a variable "MinusOne" because I want to adjust the Remove Value after an Instance has been removed (because of the index shifting as a result of that). At the beginning the value is 0 then, when the first instance has been removed, I set it to 1 so it calculates the new remove value -1 in order to get the correct index for the next element again.. however it doesn't seem to work like that.
Maybe I'm overlooking something? Is this not the correct way to adjust for the index shifting? My system is almost done and I still haven't figured this out, so I would be eternally grateful for some advice!
Thanks again for your help!
asked Oct 03 '16 at 09:12 AM in Blueprint Scripting
You should have a quick re-read of the comments in the old topic. If it's still not clear, stick some print string nodes in there and print out the index you're getting from the foreach loop and the index you're passing into the remove instance node. I think once you see the numbers you'll see what's going on.
answered Oct 03 '16 at 10:25 AM
Make an array variable of integers and store the index values you want to remove. Then on complete go through that array and remove the items of the TargetArrayList.
answered Oct 04 '16 at 10:13 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here