Disable LoadObject [Can't find file] log

Hello,
I want to disable LoadObject function log [LogLinker: Warning: Failed to load ‘\Game\MyAssetPath’ Can’t find file. ].

I need to load my asset if it exists, if not I will generate it. The problem is I don’t know how to disable that warning. Does anyone has any idea?

Can we see exactly how you are loading the object? Are you doing it in a constructor or ?

	// 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.

Try UMaterialInterface instead of UMaterialInstanceConstant?

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.

I would go this route and not try forcibly disabling the warning by filtering it.
UEditorAssetLibrary::DoesAssetExist | Unreal Engine Documentation

1 Like

@Rumzie Thank you! Worked like a charm.

As a side note:

// 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.

1 Like

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[]
			{
			}
			);
		}
1 Like

Yes, my plugin is an editor module.
If anyone uses the runtime module, please refer to @Rumzie .