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).
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
