[Bug] Instanced Static Mesh Component is broken in 4.17.1

At least RemoveInstance function is buggy, but it looks like an internal problem with indices, so other functionality may be affected as well.

Problem: when you RemoveInstance at some index, other mesh instances disappear as well. If you continue deleting mesh instances one at a time, mesh instances will (seemingly) chaotically reappear and disappear again.

Repro steps:

  1. Download attached test project;

  2. Open, start the game and press F (should delete mesh instance at 0 index);

  3. Both 0th and 4th mesh instances disappear;

  4. Keep pressing F to observe chaos.

Notes: mesh instances are added in object’s constructions script. F key is bound in level blueprint.

Same here. I have a project where my level is made up of square tiles, and depending on the type of tile, it uses a different component. I setup a test where it removes the 5th instance when I press the space bar. What happens the first time I press space bar is it removes the 5th instance, as well as the last instance. Any subsequent space bar presses just removes the last instance over and over again.
Oddly enough, the ‘Get Instance Count’ function will go down by 1 with each press, despite the first press removing 2.

Hi Flashback,

Thanks for your sample to repro the bug, i’ll see what i can do to have a fix for 4.18, as the delay for 4.17.2 is expired.

Great, thanks! This functionality is already in use in our project, would be great to have it back soon.

Updates on this? I’m relying on ISMs in my project aswell. This is a blocking bug for us.

I think there is an out of bounds error in there somewhere too, in 4.16.x I’d get it now and then working with static instances a lot

Can you provide a callstack of the issue you’re describing?

Thanks

As i said in the initial answer, it will be included in 4.18.

Is there an intended release date for 4.18?

I know you don’t read your messages but I just tried 4.18 and it does not have this fixed in your 4.18 staging build. Hopefully the developer preview will be different.

As I’m understanding it, Instanced Static Meshes will be pretty much unusable for all of 4.17? That is unfortunate.

When you’re relying on removing instances… yeah.
There is also this in HISM: Unreal Engine Issues and Bug Tracker (UE-40693)

Hi Michel,

I’m also facing big issues with ISM since 4.17, very similar to what Flashback describes. I’m now working on UE 4.17.2, and trying potential new fixes when I see one popping. So today I integrated your commit 3664690 related to the issue UE-49757 hoping it will solve my problems, but it didn’t. Before it was chaos, like Flashback explained, but now it’s still chaos, plus it asserts here:

  • Function: void FStaticMeshInstanceBuffer::UpdateInstanceData(UInstancedStaticMeshComponent* InComponent, const TArray >& InHitProxies, int32 UpdateInstanceStartingIndex, int32 UpdateInstanceIndexCount)
  • Assert: check(DestInstanceIndex != INDEX_NONE);

To the others who have issues with ISM: Could you try integrating this commit to see if it fixes your issues?

I’m using ISM components created at runtime like this (btw, see comment at the last line):

ISMComponent = NewObject<UInstancedStaticMeshComponent>(this);
ISMComponent->SetupAttachment(Center);
ISMComponent->RegisterComponent();
ISMComponent->SetStaticMesh(ISMStaticMesh);
ISMComponent->InitPerInstanceRenderData();       // Had to add this here otherwise it crashed later

And then, in the Tick of my actor, I’m calling a lot of AddInstance and RemoveInstance on them within the same frame (order and number of times of these calls vary). Apparently, everything is fine when only AddInstance are called, But when both RemoveInstance and AddInstance are called, it asserts.

The repro is simple:

  1. Create an Actor class in C++ 2)
  2. In BeginPlay, create an UInstancedStaticMeshComponent (see code above)
  3. In Tick, randomly call both RemoveInstance and AddInstance several times in various orders
  4. Observe the assertion

Please give it a try.

Thanks

HI Steeve, can you try with 4.18 Preview 3 with no code changes on your part touching this engine code, and let me know if you still have issues?

Thanks.

Hi Michel, sorry for not replying earlier. I finally upgraded to 4.18.1. No more crash. So that’s a relief. I also fixed my bug causing instances to be at wrong positions. I was previously using the Instance Indexes to update only the instances that I had to move (by saving the index when I added the instance and removing this instance by its save index), but apparently these indexes are not reliable when you start removing some of the instances (I remember I read other threads about this). In the end I decided to clear all instances and re-add them every time I need to move them.

HI Steeve,

Glad it’s finally working for you. As for instance index, the value should be usable for the duration of the game, as for saving the value to restore a state, you should also be able to use the index, unless there is something i’m not thinking (it’s been a few weeks i haven’t look at this code :wink: )
As for updating only changed/moved index, keep in mind part of the refactor that i did was exactly for this, as before it was always recreating everything from scratch when updating.

Let me know if you have some questions.

Thanks for the details. It’s all good on my side. Clearing and re-adding instances doesn’t seem to be too heavy. Thanks again for the follow up :slight_smile:

Hey, just so everyone in this thread knows, this bug persists from 4.17 to 4.18.2 and is now properly classified as an issue in the bug tracker here: Unreal Engine Issues and Bug Tracker (UE-53053)

The funny thing is it was fixed in 4.18 now it looks like the issue is back again in 4.18.2.

I don’t believe that one is actually a bug, zEh-, please see my answer here: Hierarchical instanced static mesh component Bugg - Asset Creation - Unreal Engine Forums

The bug outlined in this thread here though is absolutely killing my project. -_-