How to set icon in toolbar button?

i create a lot of custom toolbar button in here:

how to set icon?

Looks like you can use FSlateStyleSet,

But I have not figured out how to use FSlateStyleSet.

This’s my code: (it’s not work)

const FVector2D Icon16x16(16.0f, 16.0f);
const FVector2D Icon20x20(20.0f, 20.0f);
const FVector2D Icon40x40(40.0f, 40.0f);

void FMapEditor2DStyle::Initialize()
	if (StyleSet.IsValid())
	StyleSet = Create();

TSharedRef< FSlateStyleSet > FMapEditor2DStyle::Create()
	TSharedRef<FSlateStyleSet> Style = MakeShareable(new FSlateStyleSet("MapEditor2DStyle"));
	Style->SetContentRoot(IPluginManager::Get().FindPlugin("MapEditor2D")->GetBaseDir() / TEXT("Resources"));
	Style->Set("MapEditor2D.Acid_Spit", new IMAGE_BRUSH(TEXT("Acid_Spit"), Icon40x40));
	Style->Set("MapEditor2D.Diplomacy", new IMAGE_BRUSH(TEXT("Diplomacy"), Icon40x40));
	return Style;

void FMapEditor2DStyle::Shutdown()
	if (StyleSet.IsValid())

TSharedPtr< class FSlateStyleSet > FMapEditor2DStyle::StyleSet = nullptr;

FName FMapEditor2DStyle::GetStyleSetName()
	return TEXT("MapEditor2DStyle");

it look like the problem is here:
Style->Set(“MapEditor2D.Acid_Spit”, new IMAGE_BRUSH(TEXT(“Acid_Spit”), Icon40x40));

Does anyone know how to set FSlateStyleSet?

Specify the style in your command class for the buttons to pick it up

DungeonArchitectHelpSystemCommands::FDungeonArchitectHelpSystemCommands() : TCommands<FDungeonArchitectHelpSystemCommands>(
	NSLOCTEXT("DungeonArchitectHelpSystem", "DungeonArchitectHelpSystem", "Dungeon Architect Help System"),

i’m trying

Thank you.

I found the PropertyName of the Set function of FSlateStyleSet To fill in the variable name,
But my variable is an array.

this’s my code: (it not work)

Style->Set("MapEditor2D.CommandList[0]", new IMAGE_BRUSH(TEXT("Acid_Spit"), Icon40x40));

Do you know how to set the array variables style?

I solved it

There is a place where I wrote the wrong code

Awesome! Glad to hear it’s resolved

thank you :slight_smile: