Setting material on UDynamicMeshComponent

I’ve decided to try out UDynamicMeshComponent as an alternative to UProceduralMeshComponent which I got working. I’ve created a FDynamicMesh3 and called SetMesh(std::move(*dynamicMesh)) and SetMaterial(0, materialInstance) on UDynamicMeshComponent. The mesh appears but the material doesn’t. I’ve also tried ConfigureMaterialSet(). Has anybody successfully got materials working with UDynamicMeshComponent?

Have you took a look at ADynamicMeshActor?
It’s constructor sets up Material for UDynamicMeshComponent in the following way:

DynamicMeshComponent->SetMaterial(0, UMaterial::GetDefaultMaterial(MD_Surface));

See: Engine/Source/Runtime/GeometryFramework/Private/DynamicMeshActor.cpp#L13-L26

There is no more Material manipulation code in said Actor so I suspect that you have to manipulate it at runtime on your own.

Thanks, I’ll check out the source code of ADynamicMeshActor to see if there are more hints on how to use the component.

The material was been applied but not the UVs so the textures weren’t showing up.

auto mesh = new FDynamicMesh3(true, false, true, false); // check the constructor what attributes you want to enable: https://docs.unrealengine.com/4.27/en-US/API/Plugins/DynamicMesh/FDynamicMesh3/__ctor/6/

mesh->EnableAttributes();

// Add positions, uvs, normals, triangles

UE::Geometry::CopyVertexUVsToOverlay(*mesh, *(mesh->Attributes()->PrimaryUV()));
UE::Geometry::CopyVertexNormalsToOverlay(*mesh, *(mesh->Attributes()->PrimaryNormals()));

So all good now? Problem solved or is still something not working as expected? Not sure if I understand right.