# Cycle through Object array. First in first out logic. 

**URL:** <https://forums.unrealengine.com/t/cycle-through-object-array-first-in-first-out-logic/2707696>\
**Category:** Blueprint\
**Tags:** unreal-engine, Array, Blueprint, question\
**Created:** [March 20, 2026, 2:38pm UTC](https://forums.unrealengine.com/t/cycle-through-object-array-first-in-first-out-logic/2707696 "2026-03-20T14:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cindermancer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cindermancer](https://forums.unrealengine.com/u/Cindermancer)\
**Post date:** [March 20, 2026, 2:38pm UTC](https://forums.unrealengine.com/t/cycle-through-object-array-first-in-first-out-logic/2707696/1 "2026-03-20T14:38:13Z")

</div>

i have a character that throws spears. He can stick them to walls and jump on them. i

I want the player to have no more than 6 spears stuck in the wall at once. when the 7th spear is stuck, it should destroy the oldest existing spear. i believe using object arrays is the answer to my problem. my print strings show my current spear count going up. but once it comes time to spawn spear 7 and destroy spear 1 nothing happens. i can just keep throwing and counting.

heres the code.

 ![Screenshot 2026-03-20 023016](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/b/afb138ded83265d1efbc58b736a3a7d929eaa3c7.png)

 ![Screenshot 2026-03-20 023028](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/6/9866a4438571c7fceb804e8ef7543d5b7d7f953a.png)

---

<div class="post-metadata">

**Author:** ![AlienRenders](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlienRenders](https://forums.unrealengine.com/u/AlienRenders)\
**Post date:** [March 21, 2026, 6:28am UTC](https://forums.unrealengine.com/t/cycle-through-object-array-first-in-first-out-logic/2707696/2 "2026-03-21T06:28:44Z")

</div>

You can’t iterate over an array and modify it. Since you’re always removing the first element if it has 7 items, you don’t need the for loop. The is valid node and the branch node that follow it can also be removed.

---

<div class="post-metadata">

**Author:** ![Vahab](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vahab/32/1148756_2.png) [@Vahab](https://forums.unrealengine.com/u/Vahab)\
**Post date:** [March 22, 2026, 12:19pm UTC](https://forums.unrealengine.com/t/cycle-through-object-array-first-in-first-out-logic/2707696/3 "2026-03-22T12:19:15Z")

</div>

First, you do not need to count the number of added items; it is easier to obtain the length of the array instead. Second, removing an item from the array does not imply that the object will also be removed. You need to destroy the actor separately before removing it from the array.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/d/ebd69d297084cfa21b11f817dc2cb4e505b515ab.png)
