This page looks best with JavaScript enabled

Adding Thumbnails to a Slate Widget

 ·  ☕ 1 min read  ·  ✍️ Taylor

This is going to be a short one.

Sometimes you’ll want to add an asset’s thumbnail to a tool. It’s actually pretty simple! There are only four parts to the whole thing.

In your widget’s .h file, declare a ThumbnailPool…

1
TSharedPtr<class FAssetThumbnailPool> ThumbnailPool;

And then create it in the .cpp file like this:

1
ThumbnailPool = MakeShareable(new FAssetThumbnailPool(24, false));

Then to actually create your thumbnail, you need to grab the FAssetData for the asset, usually through the AssetRegistryModule:

1
2
3
4
5
   const FAssetRegistryModule& assetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
   
   FAssetData assetData = assetRegistryModule.Get().GetAssetByObjectPath(FName(*MyAssetObject.ToString()));

   TSharedPtr<FAssetThumbnail> Thumbnail = MakeShareable(new FAssetThumbnail(assetData, 128, 128, ThumbnailPool));

There is a lot you can config about your thumbnails as well, using FAssetThumbnailConfig.

Then to actually create the thumbnail widget and add it to your widget, just call MakeThumbnailWidget.

1
2
3
4
5
6
7
            SNew(SBox)
            .MaxDesiredHeight(128.f)
            .MaxDesiredWidth(128.f)
            .HAlign(HAlign_Left)
            [
               Thumbnail.Get()->MakeThumbnailWidget()
            ]

And that’s it! Go forth!

Share on