The “Create Material Instance” menu item when you right-click another material is implemented like this in FAssetTypeActions_MaterialInterface::ExecuteNewMic so you should probably be able to apply the same process in your case. The “InitialParent” of the UMaterialInstanceConstantFactoryNew is what will be set as the parent material asset of the created UMaterialInstanceConstant.
if ( Objects.Num() == 1 )
{
auto Object = Objects[0].Get();
if ( Object )
{
// Create an appropriate and unique name
FString Name;
FString PackageName;
CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackageName, Name);
UMaterialInstanceConstantFactoryNew* Factory = NewObject<UMaterialInstanceConstantFactoryNew>();
Factory->InitialParent = Object;
FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
ContentBrowserModule.Get().CreateNewAsset(Name, FPackageName::GetLongPackagePath(PackageName), UMaterialInstanceConstant::StaticClass(), Factory);
}
}
else
{
// ... code when multiple Materials are selected ...
}