Edit: the below described 100ms-lag only appears when CreateMeshSection is called with collision = true. Without collision both variants run at 0.1ms. And yes: 1000 times faster, no decimal typo.
I generate a landscape via 2D-Noise and earlier i used many PMCs with only one CreateMeshSection-Call each, which generated landscrape chunks of 20x20 square tiles. The tiles consist of 4 vertices and those are used to build 2 triangles that add up to the area of the tile.
Pretty usual stuff i guess.
Then i thought, that it should be faster to have only one PMC with which i use one CreateMeshSection-Call for every landscape chunk.
But the exact opposite happened. I measured the time for CreateMeshSection and in the first variant it ran at about 1ms and with the second variant the runtime jumped up to horrible 100ms per section. And that time measured increases about 5ms with every new MeshSection, so that it grows fast to 200ms, 300ms…
For debugging, because it seemed like a memory leak or something, i also measured the vertex- and triangle-Arrays after each CreateMeshSection and they always count 1600 vertices and 800 tris, which is how it should be (20204 verts and 20202 tris).
I measured time only around the one code line which calls CreateMeshSection:
start = FPlatformTime::Seconds();
proceduralComponent->CreateMeshSection(chunkIndex, meshSections[i].Vertices, meshSections[i].Triangles, meshSections[i].Normals, meshSections[i].UVs, meshSections[i].VertexColors, meshSections[i].Tangents, collision);
end = FPlatformTime::Seconds();
if(GEngine)
GEngine->AddOnScreenDebugMessage( -1, 15.0f, FColor::Green, FString::Printf( TEXT("time: %f"), end-start ) );
So is it just like that, that one PMC with many MeshSections is bad for performance and i should switch back to many PMCs with one MeshSection each? Or is this impossibly the cause of an impact that big and there has to be some error in the code which i couldn’t find yet?
But the strange thing is: when i change the code to use only one MeshSection by
proceduralComponent->CreateMeshSection( 0, ....
which overwrites the first MeshSection again and again ( SectionIndex 0 ) instead of generating news ones, it runs fast again with 0.1ms.
So the use of multiple MeshSections with increasing SectionIndex seems to make the difference.