How to get a particular instance of InstancedStaticMesh component?

In my actor, I created an InstancedStaticMesh component and in Construction Script I added some instances. Now later in my game, how can I get a particular instance, preferably by index?

You could create an array variable of InstanceStaticMeshComponentObjectReferences in your actor and when you create these in the construction script you could add each instance to the array variable. Then you would have an index into a variable for each created static mesh.

Maybe???

use GetInstanceTransform [UE4] Somehow get the InstanceID of InstancedStaticMesh | 9to5Tutorial

and check this Hierarchical Instanced Static Meshes Usage?

Thanks. For cases that only need to update instance transform, this solution works great! We don’t need to get the instances at all.

IIRC:
you can’t get the instances. since they technically “don’t exist”, think like particles. all there is are transforms. check forum link i posted for more info.

It all comes down to a single mesh. The HISM is a set of transforms for that mesh. You can have 1,000 of them, 1 of them, or 1 million and it’s still one mesh that’s draw that many times. The beauty of the HISM is that it’s the same single mesh’s data that is draw multiple times. That’s one HISM object with however many copies of it you want to draw. To further clarify, if I have that mesh used in 5 blueprints, it’s still one mesh.

alternative yo ucan get some data if you to use a collision (eg a line trace or a collision) and then there’s a special output pin (which i cant recall) might be called component or instance. but still is a similarish object (e.g. only the transform data). (think of a game using data oriented instead of object oriented).

thanks for detailed explanation. From a programming background, I think this ‘only one mesh instance’ concept is however controversial. As in programming, an instance is a copy of a class, we can modify every Member Variable (static variable not included) per instance basis.

Anyway, besides the terminology, this idea is great for performance.

One more thing, ‘Mark Render State Dirty’ is crucial to see immediate visual updates

yes this is a difference concept, but as you’ve noticed the word in programming is used for something not quite the same and could be confusing that’s correct.
though actually is not very different, just that this is an instance from the pov of the gpu so it’s rooted on 3d concepts and not programming concepts. afaik is called similarly on different engines. (in defense of epic). i guess it never occurred to me since i already knew the concept from other engines.
the gpu mostly cares about the transform (and maybe materials).
though these are “static mesh instances” (which means instance of static meshes), and not actor instances. so maybe that also helps remembering the difference.

for example godot also call them “instances” Godot Engine Nodes - MultiMeshInstance2D - YouTube
though godot has many similarities to ue (take with a grain of salt they’re 2 different beasts).

1 Like

you can only set the transform or remove the index by index instance, the most you can get is the component and index in a map if you need to store per instance data because you can’t get per instance data outside of the material graph for some annoying reason you can only set it