Problems with Plugin icons


I have a problem with getting an icon to appear. Probably I have done some simple error or false assumption but I just can’t understand why it will not work.

I have a plugin with a toolbar button that I want an icon with.
In the plugin StartupModule method, I have this code (which worked in another project) but it now fails.

void FMyPluginModule::StartupModule()
	StyleSet = MakeShareable(new FSlateStyleSet("MyPluginStyle"));
	FString RelPath = FPaths::ProjectPluginsDir() / TEXT("MyPlugin/Resources");
	FString FullPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*RelPath);
	UE_LOG(LogTemp, Error, TEXT("Resource Path: %s"), *FullPath);
	const FVector2D Icon40x40(40.0f, 40.0f);
	const FVector2D Icon20x20(20.0f, 20.0f);
	StyleSet->Set("MyPluginIcon", new FSlateImageBrush(StyleSet->RootToContentDir(TEXT("Icon40"), TEXT(".png")), Icon40x40));
	StyleSet->Set("MyPluginIcon.Small", new FSlateImageBrush(StyleSet->RootToContentDir(TEXT("Icon20"), TEXT(".png")), Icon20x20));


		LOCTEXT("MyPluginEdModeName", "MyPluginEdMode"),
		FSlateIcon("MyPluginIcon", "MyPluginIcon.Small"),

The log properly prints the absolute path to the folder, I have tried to replace it with the relative path as well but it does not help.

UE_LOG(LogTemp, Error, TEXT("Resource Path: %s"), *FullPath);

The folder contains the valid image icons called Icon40.png and Icon20.png

Does anyone see if I have coded something wrong here?
Do I need to register the FSlateStyleSet somewhere else or earlier?
This code works perfectly in other projects.

I found the solution and it was indeed a (minor?) error in the constructor arguments for FSlateIcon. Anyway, the solution is as follows:

		LOCTEXT("MyPluginEdModeName", "MyPluginEdMode"),
		FSlateIcon(StyleSet->GetStyleSetName(), "MyPluginIcon", "MyPluginIcon.Small"),

I had missed to add StyleSet->GetStyleSetName().

Sorry for the waste of bandwidth.

1 Like