# 4.17 Instance static mesh wrong index when removed

**URL:** <https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300>\
**Category:** Asset Creation\
**Tags:** UE4-17, Instanced-Mesh, unreal-engine, bug-report, question, Blueprint\
**Created:** [September 23, 2017, 7:12pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300 "2017-09-23T19:12:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tefel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tefel/32/1194573_2.png) [@Tefel](https://forums.unrealengine.com/u/Tefel)\
**Post date:** [September 23, 2017, 7:12pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/1 "2017-09-23T19:12:13Z")

</div>

Hello,

When I moved my project to 4.17 I realize that instance static mesh stopped working. It seems like invalid index is returned if one of the instances are removed. It only happens for specific instances.

To reproduce:

1.Create instances  
2.Use on component begin overlap and try to destroy from SwapResult-\>HitItem;  
3.Do it for few elements - Index become invalid and at some point instances are not removed anymore.

Workaround is to initialize all instances: Remove Instance, Remember all instances, Clear Instances, Add all instances.

Regards,  
Tefel

---

<div class="post-metadata">

**Author:** ![CriErr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CriErr](https://forums.unrealengine.com/u/CriErr)\
**Post date:** [September 24, 2017, 2:57am UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/2 "2017-09-24T02:57:11Z")

</div>

Can you post a screenshot of step 2 and 3?

---

<div class="post-metadata">

**Author:** ![Tefel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tefel/32/1194573_2.png) [@Tefel](https://forums.unrealengine.com/u/Tefel)\
**Post date:** [September 24, 2017, 9:36am UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/3 "2017-09-24T09:36:20Z")

</div>

[[Album] imgur.com ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/a/a/3aabdc4b6b94e0e39189c66d0ef118465258ee8f.jpeg "imgur.com") ](https://imgur.com/a/84POY)

It seems it works only in specific order from the highest to the lowest index.

---

<div class="post-metadata">

**Author:** ![CriErr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CriErr](https://forums.unrealengine.com/u/CriErr)\
**Post date:** [September 24, 2017, 10:43am UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/4 "2017-09-24T10:43:53Z")

</div>

Nah, it removes the component index of which you requesting

```
	// remove instance
	PerInstanceSMData.RemoveAt(InstanceIndex);

```

You sure, that sweep result “hit item” actually returns the index of a SM instance you hit?

---

<div class="post-metadata">

**Author:** ![Tefel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tefel/32/1194573_2.png) [@Tefel](https://forums.unrealengine.com/u/Tefel)\
**Post date:** [September 24, 2017, 1:45pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/5 "2017-09-24T13:45:46Z")

</div>

Yes blueprint I showed is not working anymore. Indexes are incorrect after first removal.  
You need workaround I suggested to make it work.

---

<div class="post-metadata">

**Author:** ![Tefel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tefel/32/1194573_2.png) [@Tefel](https://forums.unrealengine.com/u/Tefel)\
**Post date:** [September 24, 2017, 3:18pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/6 "2017-09-24T15:18:40Z")

</div>

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/b/d0b0bce3a21512244bf2fddbd2b855b8503541d4.jpeg "4.17 Instance static mesh wrong index when removed") ](https://www.youtube.com/watch?v=kMg4ynCW5D0)

---

<div class="post-metadata">

**Author:** ![CriErr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CriErr](https://forums.unrealengine.com/u/CriErr)\
**Post date:** [September 24, 2017, 8:24pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/7 "2017-09-24T20:24:59Z")

</div>

I’ve checked your video, seems like it works just fine. Here the description of remove node.

```
	/** Remove the instance specified. Returns True on success. Note that this will leave the array in order, but may shrink it. */
```

---

<div class="post-metadata">

**Author:** ![Tefel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tefel/32/1194573_2.png) [@Tefel](https://forums.unrealengine.com/u/Tefel)\
**Post date:** [September 24, 2017, 9:16pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/8 "2017-09-24T21:16:41Z")

</div>

In the video it’s not removing anything. It is returning 0 indexes. It is not removing elements anymore after switch from 4.16 to 4.17 but maybe it’s intended behavior.

---

<div class="post-metadata">

**Author:** ![CriErr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CriErr](https://forums.unrealengine.com/u/CriErr)\
**Post date:** [September 25, 2017, 12:02am UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/9 "2017-09-25T00:02:01Z")

</div>

Ok, I see now.

---

<div class="post-metadata">

**Author:** ![DK\_Buzzin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DK\_Buzzin](https://forums.unrealengine.com/u/DK_Buzzin)\
**Post date:** [March 13, 2019, 7:37pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/10 "2019-03-13T19:37:20Z")

</div>

This is because each time you remove an item, the total array of those instances is re-sized. So if you have 50 blocks there and the first one is “0”, if you remove that “0” the next block in line will then become the new “0” and the total array will become 49 instead of 50. I am dealing with a bug caused from this same issue.

In my game, a player can mine ores. Lets say there are 5 iron ore nodes on my map. If a player mines an iron ore, my code properly removes that specific iron node from the game for 20 seconds. After 20 seconds, the iron ore respawns. If I wait for the ore to repsawn before I mine another ore, the whole process works fine, but if I mine an ore while waiting for another ore node to respawn, it will remove the wrong ore node or not remove one at all because the array has been changed from its original state.

I have no idea on what a workaround would look like, but that’s the problem.

---

<div class="post-metadata">

**Author:** ![Tefel](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tefel/32/1194573_2.png) [@Tefel](https://forums.unrealengine.com/u/Tefel)\
**Post date:** [March 13, 2019, 7:44pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/11 "2019-03-13T19:44:44Z")

</div>

That was a bug in 4.16/4.17 when removing ISM it was not giving you index of correct instance. It always should in my opinion, otherwise you would never know instance you are interacting with.

But it was fixed so no worries 🙂

---

<div class="post-metadata">

**Author:** ![DK\_Buzzin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DK\_Buzzin](https://forums.unrealengine.com/u/DK_Buzzin)\
**Post date:** [March 13, 2019, 8:00pm UTC](https://forums.unrealengine.com/t/4-17-instance-static-mesh-wrong-index-when-removed/405300/12 "2019-03-13T20:00:51Z")

</div>

Okay I see. Looking at my problem a little harder revealed that the indexing isn’t the problem for me. When my instanced static meshes are set to respawn, they use two stored variable values; instance index & instance transform. So my problem stems from, if i start mining a new node before the first one respawns, I am updating those two variables so I will try to respawn in the location that I am currently mining not its original location.
