Problems with remove instance function (ISMC)

I do not know if this is my fault or engine bug because I am new to Unreal.
I’ll post it to a bug report topic, but if it’s wrong, please just point it out.

Steps to reproduce

  • Create Instanced Static Mesh Component, and Call Add Instance function to creates multiple items. Let’s say 5.

221705-pic01.png

  • And call Remove Instance to delete what’s in the middle.
    Let’s say 2. The middle is removed.

221707-pic02.png

  • Add new instance. I just added and it is successful, but the last instance is lost.

221708-pic03.png

No, it looks like it’s been removed, but it’s still there. Collision occurs,
I just can not see the mesh.

At this point I noticed that the contents of the UInstancedStaticMeshComponent::InstanceReorderTable array are as follows:

0:0 (index:instanceIndex) / 1:1 / 2:3 / 3:4 / 4:4

I think this value should not be duplicated, but I’m not sure.

  • And remove the instance I just added.

221709-pic04.png

Start with 5, remove 2, add 1, so it should be 4. But the result is three.
(and one invisible mesh)

I may be totally wrong about Instanced Static Meshes. Is it an unacceptable behavior to remove instance in the middle?
However, the official document does not say such a thing, I searched the forum, but there was no related comment.

I’ve had the same issue for quite a while. I’ve literally tried everything bar messing with the engine itself. See my post here: Certain InstancedStaticMeshComponent instances don't render in the correct place when I add and remove instances in realtime? - Rendering - Unreal Engine Forums

The only solution I’ve come across so far is to ClearInstances() and readd them all during any frame you call RemoveInstance(), but that’s more of a hack than anything.

Hi Akyton, thank you for your comments.
Your solution works well, but It’s difficult to use for large chunks. I need to find a better way for my purposes.
Anyway thank you once again.

Hi hoppang,

Thank you for the report. I was able to reproduce this behavior so I’ve created JIRA UE-53053. Our developers will be investigating further. Follow that link to monitor the status of the report.

-TJ

Thanks. It would be really great if this was fixed.