Procedural mesh not saving all of its sections to static mesh

// Create StaticMesh object
UStaticMesh* StaticMesh = NewObject();

	// MATERIALS
	TSet<UMaterialInterface*> UniqueMaterials;
	const int32 NumSections = ProceduralMeshComponent->GetNumSections();
	for (int32 SectionIdx = 0; SectionIdx < NumSections; SectionIdx++)
	{
		FProcMeshSection* ProcSection = ProceduralMeshComponent->GetProcMeshSection(SectionIdx);
		UMaterialInterface* Material = ProceduralMeshComponent->GetMaterial(SectionIdx);
		if (Material == nullptr)
		{
			Material = UMaterial::GetDefaultMaterial(MD_Surface);
		}
		UniqueMaterials.Add(Material);
	}
	// Copy materials to new mesh
	for (auto* Material : UniqueMaterials)
	{
		StaticMesh->GetStaticMaterials().Add(FStaticMaterial(Material));
	}

	FMeshDescription MeshDescription = BuildMeshDescription(ProceduralMeshComponent);
	FStaticMeshAttributes StaticMeshAttributes(MeshDescription);
	StaticMeshAttributes.Register();

	// Build the static mesh render data, one FMeshDescription* per LOD.
	TArray<const FMeshDescription*> MeshDescriptionPtrs;
	MeshDescriptionPtrs.Emplace(&MeshDescription);

	UStaticMesh::FBuildMeshDescriptionsParams BuildParams;
	BuildParams.bAllowCpuAccess = true;
	BuildParams.bBuildSimpleCollision = false;

	StaticMesh->BuildFromMeshDescriptions(MeshDescriptionPtrs, BuildParams);

	// Collision
	StaticMesh->SetBodySetup(ProceduralMeshComponent->ProcMeshBodySetup);

	//// SIMPLE COLLISION
	if (!ProceduralMeshComponent->bUseComplexAsSimpleCollision)
	{
		StaticMesh->CreateBodySetup();
		UBodySetup* NewBodySetup = StaticMesh->GetBodySetup();
		NewBodySetup->BodySetupGuid = FGuid::NewGuid();
		NewBodySetup->AggGeom.ConvexElems = ProceduralMeshComponent->ProcMeshBodySetup->AggGeom.ConvexElems;
		NewBodySetup->bGenerateMirroredCollision = false;
		NewBodySetup->bDoubleSidedGeometry = true;
		NewBodySetup->CollisionTraceFlag = CTF_UseDefault;
		NewBodySetup->CreatePhysicsMeshes();
	}

it works in 4.27 runtime.

3 Likes