Custom Icons in Unreal Engine 4

Custom icons in Unreal Engine 4.

It’s the little things that matter.

If you’re building your own custom actors and components in Unreal Engine 4, then at some point you’ll want to give them a nice icon instead of the default generic one. It’s actually pretty easy to do, but it took me quite a bit of digging since I couldn’t find a ready-made guide. It boils down to the following:

  • Create a SlateStyleSet
  • Set its ContentRoot and CoreContentRoot properly
  • Register SlateImageBrushes for your actor or component
  • Register your SlateStyleSet
  • Register your SlateStyleSet as an icon source

On startup, create and register:

TSharedRef<FSlateStyleSet> StyleSet = MakeShareable(new FSlateStyleSet("MyStyleSet"));
	
StyleSet->SetContentRoot(FPaths::EngineContentDir() / TEXT("Editor/Slate"));
StyleSet->SetCoreContentRoot(FPaths::EngineContentDir() / TEXT("Slate"));

StyleSet->Set("ClassIcon.MyActor", new FSlateImageBrush("path/to/MyActor16.png", FVector2D(16.0f, 16.0f)));
StyleSet->Set("ClassThumbnail.MyActor", new FSlateImageBrush("path/to/MyActor64.png", FVector2D(64.0f, 64.0f)));

StyleSet->Set("ClassIcon.MyComponent", new FSlateImageBrush("path/to/MyComponent16.png", FVector2D(16.0f, 16.0f)));

FSlateStyleRegistry::RegisterSlateStyle(*StyleSet.Get());
FClassIconFinder::RegisterIconSource(StyleSet.Get());

On shutdown, clean up:

FClassIconFinder::UnregisterIconSource(StyleSet.Get());
FSlateStyleRegistry::UnRegisterSlateStyle(*StyleSet.Get());
ensure(StyleSet.IsUnique());
StyleSet.Reset();

3 thoughts on “Custom Icons in Unreal Engine 4

  1. Hi, I’m trying to update my code to use this new register icon stuff as EditorIcon is now deprecated.

    Can I ask for more info about where you add the “startup” code and where you add the “shutdown code”? In the constructor and ReleaseSlateResources? You save StyleSet as a member variable within your custom object?

    • Hey Kirill,

      Thanks for the heads up! Unfortunately, this was written circa 4.16 or so – I assume a lot of things have changed that may be contributing to the crash. Hopefully this snippet still gets you in the ballpark.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.