Updating a procedural mesh section

I’m using procedural mesh component to generate my city scenes like so:

Since the scene is one dynamically generated city scene viewed from above, I really only should be rendering it in one draw call if possible, using a single mesh section.

The problem is that CreateMeshSection is extremely slow, and slows down the more vertices I give it.

As I understand it, CreateMeshSection is really for initialization. If I wanted to change the number of verts say, I’ll have to do it through this.

Instead, I could use UpdateMeshSection which disallows changing of triangle ordering. Is there a reason for this? Can I hack a version of ProceduralMeshComponent.cpp to support modifying the face ordering, even if the vertex count doesn’t change?

My plan is: create a mesh section that’s 1000000 (some big number to support everything) of verts large, then shove all of those into 0,0,0 until I need them. When I’m procedurally generating meshes, all I’m doing is setting the vertex position. However the triangle ordering will change (and that’s ok…). I really should be able to use UpdateMeshSection to update it without problems. So far this solution doesn’t work because I don’t know the triangle ordering ahead of time, as it may change.

My questions are:

  • Can ProceduralMeshComponent be modified to update triangle ordering?
  • Has anyone run into a similar issue with a more elegant solution
  • Should I be using multiple mesh sections instead? What are the performance ramification of this?

For what I experienced is that it doesn’t matter if you have let’s say 16 sections with an average vertex count of 1000 or one big section with a vertex count of 16’000, as soon as the single section or one of the smaller sections will be updated (i.e. CreateMeshSection is called upon them) it will roughly take the same time for both section to be recreated, although one of them has much fewer vertices. Therefore and from quickly looking at the code I’d suppose that calling CreateMeshSection (with collision enabled; with collision disabled it runs incredibly fast) causes the whole Component, all sections, to recreate collision.
That’s why I moved from using one PMC with a lot sections to multiple PMCs with only a few sections each and it works like a charm for me, maybe that can help you as well.