It would be wonderful if we can create our own asset menu to process assets. But it seems not that easy to achieve that. I always miss Unity when it comes to creation of a customized editor tool.
Prerequisites
First of all, it is recommended to you are guranteed to have these menus setup in the StartModule
function:
1 | void F***Module::StartupModule() |
It’s easy to know that we should release those menus in the ShutdownModule
function:
1 | void F***Module::ShutdownModule() |
The Content Browser
module loaded if you want to create customized right click menu. As a result, we need to load this module by:
1 | FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>(TEXT("ContentBrowser")); |
Core Logic
Menu Extender
For a right click function in the content browser, a menu extender should be created and added to the current menu extender array by:
1 | TArray<FContentBrowserMenuExtender_SelectedAssets>& CBMenuAssetExtenderDelegates = ContentBrowserModule.GetAllAssetViewContextMenuExtenders(); |
YourOnExtendAssetSelectionMenu
is a static function that accepts a const TArray<FAssetData>&
and returns a TSharedRef<FExtender>
:
1 | static TSharedRef<FExtender> YourOnExtendAssetSelectionMenu(const TArray<FAssetData>& SelectedAssets) |
Here another function has just came to us. We still need an AssetExtenderFunction
which accepts an FMenuBuilder&
and an array of FAssetData
. We add menu entry here to eventually add a button by:
1 | static void YourAssetExtenderFunc(FMenuBuilder& MenuBuilder, const TArray<FAssetData> SelectedAssets) |
Filtering the Selected Asset
We always need to add some menu to the specific asset. For example, Find Skeleton
button would only appear in the right-click menu for a Animation Sequence Base
asset:
We can filter asset data type in YourAssetExtenderFunc
like this:
1 | for (auto AssetIt = SelectedAssets.CreateConstIterator(); AssetIt; ++AssetIt) |
Add Menu Entry
Simply use a Lambda function for this like:
1 | MenuBuilder.AddMenuEntry( |
And that should work.