# Can't remove item from index

**URL:** <https://forums.unrealengine.com/t/cant-remove-item-from-index/457170>\
**Category:** Blueprint\
**Tags:** removal, unreal-engine, UE4, question, Blueprint\
**Created:** [October 19, 2019, 4:22pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170 "2019-10-19T16:22:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![meme2sin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@meme2sin](https://forums.unrealengine.com/u/meme2sin)\
**Post date:** [October 19, 2019, 4:22pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/1 "2019-10-19T16:22:36Z")

</div>

Basically what the title says. I have tried removing an item with the remove item and remove index nodes but they don’t work or better said they only work temporarily. The length of the array changes but then it goes back to normal when the for loop is called again. I read that it was a bug that happened because of me doing it in a function so I tried doing it in the main blueprint but that didn’t work either. Any ideas?

 ![290498-arraybug.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/f/f/1ffcd127eab133e79484158b2fd16be0ac3457d0.png)

---

<div class="post-metadata">

**Author:** ![BlueMind\_Studio](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BlueMind\_Studio](https://forums.unrealengine.com/u/BlueMind_Studio)\
**Post date:** [October 19, 2019, 5:18pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/2 "2019-10-19T17:18:47Z")

</div>

What type of array is your AllInstances? I haven’t seen a find node with 3 inputs before.

---

<div class="post-metadata">

**Author:** ![meme2sin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@meme2sin](https://forums.unrealengine.com/u/meme2sin)\
**Post date:** [October 19, 2019, 6:13pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/3 "2019-10-19T18:13:54Z")

</div>

It is a structure type variable with an integer and a transform. More info on [here](https://docs.unrealengine.com/en-US/Engine/Blueprints/UserGuide/Variables/Structs/index.html)

---

<div class="post-metadata">

**Author:** ![rolffson](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rolffson/32/470238_2.png) [@rolffson](https://forums.unrealengine.com/u/rolffson)\
**Post date:** [October 19, 2019, 7:06pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/4 "2019-10-19T19:06:09Z")

</div>

may not be the cause, but just for better understanding:  
  
what exactly do you mean with “during the for loop”?  
  
There’s a return node at the end of the loop body, so it seems it won’t do any further loop run after remove\_index.

---

<div class="post-metadata">

**Author:** ![meme2sin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@meme2sin](https://forums.unrealengine.com/u/meme2sin)\
**Post date:** [October 19, 2019, 7:22pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/5 "2019-10-19T19:22:50Z")

</div>

The for loop is called with the tick event. I’ll edit it now.

---

<div class="post-metadata">

**Author:** ![TRI99ER](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TRI99ER](https://forums.unrealengine.com/u/TRI99ER)\
**Post date:** [October 20, 2019, 3:32pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/6 "2019-10-20T15:32:31Z")

</div>

It’s not a good practice to call loops every tick.

---

<div class="post-metadata">

**Author:** ![rolffson](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rolffson/32/470238_2.png) [@rolffson](https://forums.unrealengine.com/u/rolffson)\
**Post date:** [October 20, 2019, 3:36pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/7 "2019-10-20T15:36:12Z")

</div>

maybe it helps if we could have a screenshot of where the variable “all instaces” gets set.

---

<div class="post-metadata">

**Author:** ![TRI99ER](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TRI99ER](https://forums.unrealengine.com/u/TRI99ER)\
**Post date:** [October 20, 2019, 3:48pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/8 "2019-10-20T15:48:04Z")

</div>

Are you sure it will find an element with those Block Id and Transform values?

Also it may not work correctly on Event Tick, because For loop may be going more than one tick, before it removes index.  
Anyway calling loop on Event Tick may lead to unpredictable results, especially if that loop is expected to run for large number of iterations and/or process complex data. Basically there will exist multiple instances of this function, all processing same value (your array).

Try redesigning your code to not call this function every tick and then comment, if problem persists.

---

<div class="post-metadata">

**Author:** ![Schmicki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Schmicki](https://forums.unrealengine.com/u/Schmicki)\
**Post date:** [October 20, 2019, 10:57pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/9 "2019-10-20T22:57:45Z")

</div>

Could you please show us the whole Function?

---

<div class="post-metadata">

**Author:** ![meme2sin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@meme2sin](https://forums.unrealengine.com/u/meme2sin)\
**Post date:** [October 21, 2019, 8:31pm UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/10 "2019-10-21T20:31:28Z")

</div>

Alright, turns out that this entire problem was just an illusion. I just found out two actors with the same array were being spawned in the same place perfectly on top of one another so when I called the function to remove one item from the array I would print the length from the array, remove the item, print the length again and then without realizing it I did the same with the actor which gave the illusion that it wasn’t being deleted the first time. That doesn’t mean you guys wasted your time though. All your suggestions really helped in making my code 10 times easier to read and probably more efficient. Sorry I couldn’t reply earlier but I have been without internet for the whole day.

---

<div class="post-metadata">

**Author:** ![TRI99ER](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TRI99ER](https://forums.unrealengine.com/u/TRI99ER)\
**Post date:** [October 22, 2019, 10:50am UTC](https://forums.unrealengine.com/t/cant-remove-item-from-index/457170/11 "2019-10-22T10:50:28Z")

</div>

Good thing it works now!
