Help understanding Arrays and ForeachLoop

I am trying to destroy the previous actor out of an array I make from actors that spawn every time I press a button,

Ok, So I press tab, I spawn an actor and put it into an array. First one has an index of 0. I have the foreachloop make sure the index is above 0 so it doesnt destroy anthing the first time.

I press tab again, now the for each loop is reading both of the items I have in the array, the first one is index 0, the second is index 1, greater than zero so I take that number, I subtract 1 from it to get an int of 0, I re-get my array and tell it to destroy the actor with an index of 0. My plan would be I press the spawn button again and the next array now only has 2 items in it, one with an index of 1 and one with 2, i subtract one from the 2 to get an int of 1 and have the get function tell destroy actor to now destroy the actor with an index of 1…

The problem is that when I press the spawn button the second time it is telling me it can’t access it because of the pending kill. I have tried using destroy actor when finished with the same problem.

And anyways the real thing I want to understand is I am only calling to destroy the actor with an index of 0, not the one I just created with the second button press with an index of 1, so this shouldn’t be a problem, thanks!!!

You should try removing the index or item after you destroy it, that way there won’t be an actor pending kill.

Drag off the array element of the loop and type destroy actor - attach this to the true pin of the branch - remove the auto-destroy node

That did it, thanks!! Also for all you out there with a problem that is similar, the root problem was at first the spawn actor didnt have it set to spawn no matter what