Hey guys,
I’m currently creating a procedural mesh that has multiple subcomponents.
There are about 600 subcomponents in all.
However, when compile and start, the mesh itself looks fine in for, but I get really poor performance.
I’m not exactly sure why either. Here is my code followed by my question.
//Start voxel building and add as subcomponents.
for (int x = 0; x < voxelMatrix.Num(); x++)
{
for (int y = 0; y < voxelMatrix[x].Num(); y++)
{
for (int z = 0; z < voxelMatrix[x][y].Num(); z++)
{
if (!voxelMatrix[x][y][z].isEmpty)
{
//Component Name
char nameString[20];
sprintf_s(nameString, "voxel-%u-%u-%u", x, y, z);
//Create subcomponent sig
mesh = CreateDefaultSubobject<UProceduralMeshComponent>(FName(nameString));
//Set up collision delegate
mesh->OnComponentHit.Add(onCollisionDelegate);
mesh->OnComponentBeginOverlap.Add(onCollisionDelegate);
//Build voxel tris and set tris to component
mesh->SetProceduralMeshTriangles(voxelBuilder.BuildVoxel(&voxelMatrix[x][y][z]));
mesh->AttachTo(startMesh);
}
}
}
}
Here is some supporting code for building the mesh components:
bool UProceduralMeshComponent::SetProceduralMeshTriangles(const TArray<FProceduralMeshTriangle>& Triangles)
{
ProceduralMeshTris = Triangles;
UpdateCollision();
// Need to recreate scene proxy to send it over
MarkRenderStateDirty();
return true;
}
void UProceduralMeshComponent::UpdateCollision()
{
if (bPhysicsStateCreated)
{
DestroyPhysicsState();
UpdateBodySetup();
CreatePhysicsState();
// Works in Packaged build only since UE4.5:
ModelBodySetup->InvalidatePhysicsData();
ModelBodySetup->CreatePhysicsMeshes();
}
}
If I create the object as one big mesh (no subcomponents). There is absolutely no performance issue at all. I understand that now each component has it’s own physics mesh and all, but I still can’t believe that 70 sends the system to it’s knees.
So, is there anyway I can better resolve performance with mutliple subcompnonets?