Generate Procedural Mesh

Does anyone has any hints for me to improve performance when generating a voxel cube world?
My current approach is that I have several lists in which I store chunks that should be loaded, destroyed and those that are currently loaded.
In my update method I mark e.g. 16x16x16 chunks to be loaded. Those chunks are packed to batches that should be executed by several FQueuedWork objects using a FQueuedThreadPool. The worker threads push the resulting triangle lists for every chunk (still batched in multiple chunk triangle list per packet) into an TQueue that is handled by the main thread to spawn the chunks.

To spawn the chunks I “unbatch” the chunk triangle lists and put them into an sperate std::queue (I do this to prevent slowing the system by many parallel FQueue calls and so there is only one push by one worker and those results are extracted in the main thread and then the chunks are spawned as ProceduralMeshComponent that are attached to the generator actor using this code:



UProceduralMeshComponent* mesh = NewObject<UProceduralMeshComponent>( this );
			mesh->RegisterComponentWithWorld( world );
			mesh->AttachTo( RootComponent );
			mesh->SetProceduralMeshTriangles( triangles );
			mesh->SetComponentTickEnabled( false );
			mesh->SetMaterial( 0, worldMaterial );
			mesh->SetRelativeLocation( FVector( pos.chunkPosX * chunkSize * blockSize, pos.chunkPosY * chunkSize * blockSize, pos.chunkPosZ * chunkSize * blockSize ) );
			AddOwnedComponent( mesh );


I don’t spawn all the chunks at once but try to share them over multiple frames (using a queue that has a maximum duration time).

But I still get massive frame drops and the terrain is mostly not spawned fast enough so I can walk faster from one end to the other than spawning new chunks. The problem is, that the main bottle neck seems to be the spawning itself - especially the method call mesh->SetProceduralMeshTriangles( triangles ) takes much time and for some chunks it needs about 60 to 80 ms to spawn one single chunk object.

I have tried to reduce the triangle memory that has to be copied by using only uint8 as vertex coordinates, but it is still too slow. I also do some basic optimization for creating the chunk triangles (only create cube faces that are visible and not hidden by neighboring cubes).

So in my eyes this should be pretty fast and I have no idea what I could to to speed up chunk spawning to get a smoothly generated terrain without frame drops and without me easily walking out of the world. So do you have any special hints to improve my performance even more? Or did I something wrong? Thanks, for your help.

@JohnnyBeans78: I don’t have any issues with 4.7 and I have a graphical representation. But I created a new 4.7 project so I cannot say if it would work using 4.5 or 4.6. But I didn’t use something special.