Download

Instanced Static Mesh, Removing Instance Issue

So there is this cool video from epic featuring instanced meshes. Canon Man Tutorial: Hierarchical Instanced Static Meshes | Live Training | Unreal Engine - YouTube . It basically says that instead of deleting the x index in the hierachy. it gets replaced by the last index of it and thats going to be removed. so everytime you remove an index of it, the last index will be moved there. thats what ruined the structure. simple fix would be to use a normal instanced mesh (ISM) instead of an hism. that worked for me.

I tried emulating erase and swap, but they still get shuffled unknown way. That issue remains unsolved for me for 13 months. How to restore correct indices after removal from HISM?
**Update: **I tried again. Yes, it’s erase and swap. That feel when you fix 13-month bug.

In case anyone needs it, index restoration is something like this:



int instancesNumber = MeshComponent->GetInstanceCount();
for (auto& x: instances) {
    if (x.instanceIndex == instancesNumber) {
        x.instanceIndex = deletedInstance.instanceIndex;
        break;
    }
}


What about removing instances after a certain number of hit. I’m able to remove instances without any problem but I want the player to have to interact multiple times with the instance before removing it.

Gonna link those 2, seems quite related:

you can just use the “Clear Instances” Node