// Try to find Material Instance in Content Browser
MI_Material = nullptr;
MI_Material = LoadObject<UMaterialInstanceConstant>(nullptr, *(PackageName + Name));
// Spawn Material Instance if not found
if (!MI_Material )
{
MI_Material = CastChecked<UMaterialInstanceConstant>(
AssetToolsModule.Get().CreateAsset(Name,
FPackageName::GetLongPackagePath(PackageName),
UMaterialInstanceConstant::StaticClass(),
Factory)
);
}
I use it in PluginButtonClicked function in plugin, and it works perfectly.
The log is completely correct, which doesn’t surprise me. If the plugin doesn’t find the asset in the path, I will generate the asset, that’s how I want to achieve.
The material instance is also correct. The plugin will be executed repeatedly. That will do additional processing when it detects that the material instance already exists.
What I want is to hide the log when I first generate the material instance, in other words when LoadObject fails.
// in Your_Plugin.Build.cs
PrivateDependencyModuleNames.AddRange(
new string[]
{
"Projects",
"InputCore",
"EditorFramework",
"UnrealEd",
"ToolMenus",
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"EditorScriptingUtilities" // need to add this line
// ... add private dependencies that you statically link with here ...
}
);
Right click on your project and execute Generate Visual Studio project files.
Is this in an editor module already? If it is then what you have there linking against the editor module is fine. If you’re ever finding yourself needing this for a runtime module, that will not properly compile in a packaged build. To get around this you’ll need something like this.
if (Target.Type == TargetType.Editor)
{
PrivateIncludePathModuleNames.AddRange(
new string[]{
});
PrivateDependencyModuleNames.AddRange(
new string[]
{
}
);
}