How to make copy of master material and apply to StaticMesh

I’m writing a plugin for UE4 and am able to get my master material, now I want to be able to apply it to a mesh and make changes on the mesh material rather than the master material.
I have a UStaticMesh object on which I want to apply the Master Material.



UStaticMesh *myMesh = Cast<UStaticMesh>(ImportedAssets[0]);
FString matPath = "Material'/Game/MasterMaterial.MasterMaterial'";
UMaterialInterface * material = Cast<UMaterialInterface >(StaticLoadObject(UMaterialInterface::StaticClass(), nullptr, *(matPath)));
if (material)
{
// apply a copy of the master material on the mesh so that it can be edited
}



UMaterialInterface* MyMaterial;
UMaterialInstanceDynamic* MyMaterialInstance = UMaterialInstanceDynamic::Create(MyMaterial, this);