How to add a dynamic material to a procedural mesh?

I cannot figure out how to add a UMaterialInstanceDynamic to a UProceduralMeshComponent.

The function UProceduralMeshComponent::SetMaterial() expects a UMaterialInterface for its input, but I tried casting my MID like this:

ProceduralMesh->SetMaterial(0, Cast<UMaterialInterface>(DynamicMaterial))

But it doesn’t work, the Procedural Mesh ends up without a material. And yet, in Blueprint, you can very easily add a Material Instance Dynamic to a Procedural Mesh.

What am I doing wrong?

It should just work with

ProceduralMesh->SetMaterial(0, DynamicMaterial)

, because UMaterialInstanceDynamic inherits from UMaterialInterface.

Huh, you’re totally right! I swear I tried that and it didn’t work. Thanks!