Create all instances of InstancedStaticMeshComponent at once

Hey guys!

I’m working on a project where I want to render a huge amount (multi-million) of primitives (e.g. quads) in the unreal engine. I started using the InstancedStaticMeshComponent and it looks really promising. But when I add a lot of instances, calling the “AddInstance”-method for every instance really slows down the whole thing. Therefore I was wondering if I could basically allocate/initialize all instances at once (they actually all have the same position, orientation, material, etc.), but they don’t get rendered.
Does anyone know how to achieve this? Any help would be much appreciated!

My current state (not working):

		x = new FStaticMeshInstanceData(true, false);
		x->AllocateInstances(pointCount, true);
		
		StreamComponent->InitPerInstanceRenderData(false, x);
		StreamComponent->PerInstanceRenderData->UpdateFromPreallocatedData(StreamComponent, *x, true);
		StreamComponent->PerInstanceRenderData->InitResource();
		StreamComponent->MarkRenderStateDirty();

solved: was missing the PerInstanceSMData:

	TArray<FInstancedStaticMeshInstanceData> smdata;
	for (int i = 0; i < pointCount; i++)
		auto NewInstanceData = new(smdata) FInstancedStaticMeshInstanceData();
	StreamComponent->PerInstanceSMData = smdata;

Hi hausfrau87.

I’m actually trying to do something really similar to this, and I was wondering if you’d be willing to post a slightly expanded version of this code? I’ve been trying to get what you have here working, but with no success.

Thanks.