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.
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.
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.
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:
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:
Create an Actor class in C++ 2)
In BeginPlay, create an UInstancedStaticMeshComponent (see code above)
In Tick, randomly call both RemoveInstance and AddInstance several times in various orders
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.
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 )
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.
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)