How do I keep a valid reference to a InstancedStaticMesh instance?

Hi guys!

I’m in the process of creating some (runtime!) procedurally generated levels, and I very quickly ran into the performance issue with spawning standard static meshes. I turned to InstancedStaticMeshes which has vastly improved performance (as expected) but now I’ve run into the issue of trying to keep a valid reference to the specific instance related to a specifically spawned object.

As an example: I create several InstancedStaticMesh instances, but I decide (at runtime) that I want to delete a specific one, and replace it with something else. Due to the internal use of TArray inside InstancedStaticMesh I can keep an index for each instance however those indexes are immediately invalidated as soon as I remove an element from said array.

Is there a system I have not found yet, which allows me to keep a valid reference to a specific instance of an InstancedStaticMesh, so that I can Add/Delete/Update/Move/Whatever that specific instance without destroying all other references in the process?

Thanks! :slight_smile:

Hi Grey, have you had any luck with this? I’m attempting to do something similar.

No luck sorry mate.
I am building my own copy of the engine from source though, so I changed how InstancedStaticMesh stores it’s duplicates internally.
Due to the way I handle my duplicates (all at discreet whole-number coordinates), I can find specific instances in a simple brute-force loop over the entire list so my changes aren’t really good enough for offering back to the engine.

OMG, this would make these things so much more useful if we had references to them!!!

Not having that is making a project impossible. :’(

Either that or I’m an idiot.

Granted, my idea requires millions of items, and uses way too much memory as separate Static Meshes.

glad to finally find some co-miserators on this one. i did get this one to work: InstancedStaticMesh->RemoveInstance(4); all attempts to make references fail.