# Reverse for loop not removing isntances.

**URL:** <https://forums.unrealengine.com/t/reverse-for-loop-not-removing-isntances/486430>\
**Category:** Audio\
**Tags:** Instanced-Mesh, unreal-engine, remove, loop, question, Blueprint\
**Created:** [July 20, 2021, 4:06pm UTC](https://forums.unrealengine.com/t/reverse-for-loop-not-removing-isntances/486430 "2021-07-20T16:06:46Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [July 20, 2021, 4:25pm UTC](https://forums.unrealengine.com/t/reverse-for-loop-not-removing-isntances/486430/5 "2021-07-20T16:25:32Z")

</div>

If you remove an index, _some_ other indexes will be redistributed - jumbled. It does not matter here that you’re doing it in reverse - the indexing within the HISM does not work like a regular array where elements are neatly ordered; they cannot be discarded / (re)moved around while others keep their spot.

You cannot have a situation where there is no index 5 in HISM with 10 instances. The moment you remove 5, number 8 may become 6. 😑

If you want to remove a bunch of indexes, add them to an array and [bulk-remove][1] _in one go_ rather than one-by-one. There are linked examples of this in the other thread where we talked about casting.

* * *

Or even better, have a look at how [Sets][2] work - they offer very efficient operations that work really well with HISM indexes. As in:

 ![344583-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/f/b7f9682d8ebb36ae79c43166a5026f0396d9a2f8.png)

This way you do not even need to use AddUnique. A Set will ensure values are unique. And there’s no more iteration, it all happens in one go.

---

_[View the full topic](https://forums.unrealengine.com/t/reverse-for-loop-not-removing-isntances/486430)._
