[Solved] Asset picker widget for editor utility widget

I’m trying to add an asset picker (the same kind used all over the editor) to an editor utility widget, and I thought this would be simple but I guess there’s no support for it yet?

My research has led me down a Slate rabbit hole, with little to show for it. Apparently **SObjectPropertyEntryBox** is a slate widget type I could use? I made a UWidget subclass with **SNew(SObjectPropertyEntryBox)** etc in **RebuildWidget()** and that does result in an asset picker, but I can’t seem to get **OnObjectChanged** hooked up properly. It expects a reference to a callback function with **const FAssetData& Data** as a parameter, which seems pretty straightforward, but deep down in the slate codegen somewhere it calls **CreateSP(StaticCastSharedRef<UserClass>(InUserObject->AsShared()), InFunc, Vars...)** where **UserClass** is the widget type that gets passed to **OnObjectChanged** (my widget type), and **InUserObject is a **UserClass*. And the handler function in question is expected to be a member of that class, I think? e.g. .**OnObjectChanged(thi****s, &UMyAssetPickerWidget::OnAssetChanged)**. The problem is, my UWidget subclass isn’t **TSharedFromThis** so it doesn’t have **->AsShared()** and the compiler chokes there.

If there’s an easier way to do this, please let me know. Otherwise, how can I get a **SObjectPropertyEntryBox** or something similar into a widget I can use in UMG?

Okay, after a good night’s sleep I’ve figured it out. **OnObjectChanged has 22 (!) overloads, and the one I was using was for binding delegates on non-UObjects. There’s another overload, **OnObjectChanged(const FOnSetObject&) that takes a reference to a **FOnSetObject **which is a delegate type declared in **PropertyCustomizationHelpers.h**. So, I added a **FOnSetObject** delegate to my **UWidget** class, passed a reference to that into **OnObjectChanged** and used **BindUObject** on the delegate in my **UWidget** class’s constructor to bind that delegate to a member function that takes **const FAssetData&** and voilà! A working callback.

Edit:

Actually, there’s an even simpler way to do this. You can cut out the delegate middle man and just use the **OnObjectChanged_UObject()** variant which expects a UObject and its member function. It’s so much easier to figure this stuff out when intellisense actually decides to work.

2 Likes

Have you tried turning the thumbnail on and were you able to do so successfully? The thumbnail pool thing baffles me to this day.

@BlackFangTech if you are still looking for a solution for Thumbnails, you can try this:

FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked(“LevelEditor”);
TSharedPtr ThumbnailPool = LevelEditorModule.GetFirstLevelEditor()->GetThumbnailPool();

Pass that ThumbnailPool to SObjectPropertyEntryBox