Procedural Mesh Generation - Optimisation questions

Hi, I have an optimisation question.

I am creating a semi-large number of (non-complex) meshes to represent terrain tiles, but I find that attaching them as component meshes to an actor is a bit slow.

I only have the single actor in the scene which I attach all component meshes to. It’s not uncommon to have 100 - 200 of these component meshes on screen at any one time, so I’m noticing an initial slowdown if 30-50 come through to be generated / attached in one frame, then a general application slowdown (fps) with 100+ meshes rendering.

My questions are: Can I speed up this mesh generating / attaching process somehow (Attaching components to an actor in bulk? Can or should I do this in a background thread?). And what can I do / disable to stop the application slowing down when I start rendering a lot of meshes?

I have a blank scene at the moment with just a generic sky / atmosphere effects, and generate the meshes into that. I’m hesitant to stop collision data being generated (even though it might help), as I would like camera-on-terrain checks.

How I’m setting up the actor:



FActorSpawnParameters sp;
sp.Name = "Terrain";
sp.bNoCollisionFail = true;

UWorld *world = GetWorld();

_actor = (AIonTerrainActor*)world->SpawnActor(AIonTerrainActor::StaticClass(), &FVector::ZeroVector, &FRotator::ZeroRotator, sp);
_actor->PrimaryActorTick.bCanEverTick = true;


How I’m creating and attaching each component mesh:



UGeneratedMeshComponent *componentMesh = NewNamedObject<UGeneratedMeshComponent>(_actor, ss.str().c_str());

// Snip, creating mesh 'triangles' here

componentMesh->SetGeneratedMeshTriangles(triangles);
componentMesh->bVisible = true;
componentMesh->bOwnerNoSee = false;
componentMesh->SetHiddenInGame(false);
componentMesh->RegisterComponent();


I am using the Procedural Mesh Generation tutorial code for the most part.

Any tips or ideas would be awesome, thanks.

Looking at this further it seems the jerky-ness I’m seeing happens when I call:


componentMesh->RegisterComponent();

I’m still not sure why this function would be so intensive. Once objects are in the scene rendering the jerky-ness goes away, but returns when I need to call the above function multiple times again.

Is there a way to bulk register components to an actor? Say if I need to add 30 mesh components in a tick, rather than call ‘RegisterComponent’ 30 times (once after each mesh construction), is there a way I can register them all at once after I’ve built them all?