Unable to set material of Static Mesh Component with a generated Static Mesh in build

Hi, I am converting a Procedural Mesh into a Static Mesh, and then assigning it a material using the Set Material node.
This works well in editor mode, but when I make a packaged build the material does not show up. It instead shows the light grey / dark grey checkerboard pattern.

Here is my code for converting the Procedural Mesh into a Static Mesh

UStaticMesh* UProceduralHelperFunctionsBPLibrary::ConvertToStaticMesh(UProceduralMeshComponent* ProceduralMesh, UMaterialInterface* Material)
{
	if (!ProceduralMesh)
		return nullptr;

	FMeshDescription MeshDescription = BuildMeshDescription(ProceduralMesh);

	// If we got some valid data.
	if (MeshDescription.Polygons().Num() > 0)
	{
		// Create StaticMesh object
		UStaticMesh* StaticMesh = NewObject<UStaticMesh>(ProceduralMesh/*Package, MeshName, RF_Public | RF_Standalone*/);
		StaticMesh->InitResources();

		// Enable CPU access for the static mesh
		StaticMesh->bAllowCPUAccess = true;

		StaticMesh->SetLightingGuid();

		// Add source to new StaticMesh
		auto Desc = StaticMesh->CreateStaticMeshDescription();

		// Assuming you have access to the MeshDescription object
		FStaticMeshAttributes StaticMeshAttributes(MeshDescription);
		auto VertexInstanceColors = StaticMeshAttributes.GetVertexInstanceColors();

		// Set vertex colors explicitly
		for (const FVertexInstanceID VertexInstanceID : MeshDescription.VertexInstances().GetElementIDs())
		{
			FVector4f VertexColor(0.0f, 0.0f, 0.0f, 0.0f); // Set the initial vertex color to grey (0, 0, 0, 0)
			VertexInstanceColors[VertexInstanceID] = VertexColor;
		}

		Desc->SetMeshDescription(MeshDescription);
		// buildSimpleCol = false, cause it creates box collision based on mesh bounds or whatever :(
		StaticMesh->BuildFromStaticMeshDescriptions({ Desc }, false);

		// Create collision data for the static mesh
		StaticMesh->CreateBodySetup();
		UBodySetup* NewBodySetup = StaticMesh->GetBodySetup();
		NewBodySetup->BodySetupGuid = FGuid::NewGuid();
		NewBodySetup->bGenerateMirroredCollision = false;
		NewBodySetup->bDoubleSidedGeometry = true;
		NewBodySetup->CollisionTraceFlag = CTF_UseComplexAsSimple;
		NewBodySetup->DefaultInstance.SetCollisionProfileName(UCollisionProfile::BlockAll_ProfileName);

		// Copy convex elements from ProceduralMesh's BodySetup
		NewBodySetup->AggGeom = ProceduralMesh->ProcMeshBodySetup->AggGeom;

		// Create physics meshes
		NewBodySetup->CreatePhysicsMeshes();

		return StaticMesh;
	}

	return nullptr;
}

And here is how I use it in Blueprints:

Does anyone know how I can fix this issue?
Thanks

I am having the same problem.
Does anyone know a solution?

I am trying to do the same thing too. I can print out the material name from the procedural mesh and see that the generated static mesh also has that material assigned, but it’s somehow not rendering correctly.

It works in editor, so I’m wondering if it that’s the only way it works.