[C++] instanciate static mesh components with for loop

Hi guys,

I’m following the [chess tutorial] (A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums) using blueprints and now, for learning purposes, trying to “translate” it to C++.

My problem now (at the very beginning :p) is how can I instantiate static mesh components using a for loop?

for (int numberOfSquares = 0; numberOfSquares < 64; numberOfSquares++)

Should I create 64 UStaticMeshComponents one by one?

UStaticMeshComponent* squareMeshxx = CreateDefaultSubobject(TEXT(“squareMeshxx”));

or can I use an array of UStaticMeshComponents? If yes, how?

No you create an instance of instanced mesh component and than in loop you just call AddInstance passing in transform of the mesh and it will return the index of new added mesh

Hi, thanks for your answer. Do you know any place I can find an example of this in use? I found one here : InstancedStaticMeshComponent->AddInstance Performance - C++ - Unreal Engine Forums and tried to apply the same solution, but didn’t found any AddInstance member.

Hey man, thanks a lot.