Get dynamic material instance?

Hello

How can I get the dynamic material instance from my static mesh?

Here are some things I’ve tried:

// Returns UMaterialInstance, which wont let me edit scalar params
hand_hammer->GetMaterial(0); 

// Returns null
Cast<UMaterialInstanceDynamic>(hand_hammer->GetMaterial(0));

// Returns an empty material (the default grey)
UMaterialInstanceDynamic::Create(hand_hammer->GetMaterial(0), this);

All I want to do is modify the scalar params on the material instance that’s on the mesh.
Any help would be very appreciated.

Thanks!

When the mesh is first put into the world, you need to create a dynamic instance version of the material and assign back to the mesh material slot.

I’ve tried that in a number of ways (see my 3rd line of code) but creating an instance always seems to appear as an empty material. How would I properly go about doing this? Also do I need to store a reference to the dynamic instance? Or will I then be able to access it through GetMaterial(0) somehow?