# Loop thru array and remove items/actors

**URL:** <https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088>\
**Category:** Audio\
**Tags:** unreal-engine, loop, question\
**Created:** [March 4, 2015, 5:40am UTC](https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088 "2015-03-04T05:40:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tas](https://forums.unrealengine.com/u/tas)\
**Post date:** [March 4, 2015, 5:40am UTC](https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088/1 "2015-03-04T05:40:53Z")

</div>

Hello,

Here is what im trying to do:

1. Create array of actors
2. Loop thru it every second and check if actor is above pawn
3. If it is, then delete actor

Here is my implementation in BP, but logic is wrong and it doesnt quite work as expected. I know more or less whats wrong, but dont know how to fix it. Any tips ?

Another way would be to create multibox above pawn and kill on overlap. Before I try this approach I want to know how to do this with loops and arrays.

Thanks!

 ![32137-loop1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/8/1e8618838787c3f134e2dd1332f06076f1cc1822.jpeg)

![32138-untitled.gif](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/7/737336835b6836cd1c2e40f02634224e2a9b6636.gif)

---

<div class="post-metadata">

**Author:** ![alperenakyuz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alperenakyuz](https://forums.unrealengine.com/u/alperenakyuz)\
**Post date:** [March 4, 2015, 11:34am UTC](https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088/2 "2015-03-04T11:34:46Z")

</div>

You need to use a ForEachLoop instead of a ForLoop. It’s pretty self-explanatory and straightforward to use. It would help you get rid of all the “Get” nodes

---

<div class="post-metadata">

**Author:** ![tas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tas](https://forums.unrealengine.com/u/tas)\
**Post date:** [March 4, 2015, 5:29pm UTC](https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088/3 "2015-03-04T17:29:50Z")

</div>

I tried to iterate backwards this loop, to fix deletion of wrong actors. If I use ForEachLoop and iterate forward, I get similar result. Wrong one. Do you see the issue on the anim gif ?

---

<div class="post-metadata">

**Author:** ![alperenakyuz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alperenakyuz](https://forums.unrealengine.com/u/alperenakyuz)\
**Post date:** [March 15, 2015, 10:23pm UTC](https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088/4 "2015-03-15T22:23:26Z")

</div>

I see the problem: it’s because you’re removing indices while within the loop. When you remove an index the entire array shifts, that’s why it’s skipping one.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3933a5bf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3933a5bf](https://forums.unrealengine.com/u/anonymous_user_3933a5bf)\
**Post date:** [June 11, 2015, 7:00pm UTC](https://forums.unrealengine.com/t/loop-thru-array-and-remove-items-actors/309088/5 "2015-06-11T19:00:47Z")

</div>

Makes sense and I’ve done this plenty of times in code but how are we supposed to decrement the current index using blueprint?
