Hi everyone! I’m trying to add an option to the asset context menu from the Content Browser (when you right click on an asset). I’m pretty clueless… To extend the Level Editor you need to do this:
But there is no GetMenuExtensibilityManager() for the Content Browser module. I read on the forum that I should use ContentBrowserModule.GetAllAssetViewContextMenuExtenders() but I do not know what to do with the return type from this function. If someone could just point me to the right direction I’d appreciate. Thanks!
I’m also trying to figure this one out. It looks like the AssetManager plugin is a good reference to start from. It adds the “View References” and other commands to the Content Browser’s context menu. And it works not only for assets, but for folders as well.
I have done this quite a while ago - not sure if it is still compatible with recent UE Versions. Give it a try
void FYourPlugin::StartupModule()
{
FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>(TEXT("ContentBrowser"));
TArray<FContentBrowserMenuExtender_SelectedPaths>& MenuExtenderDelegates = ContentBrowserModule.GetAllPathViewContextMenuExtenders();
// Create new delegate that will be called to provide our menu extener
MenuExtenderDelegates.Add(FContentBrowserMenuExtender_SelectedPaths::CreateRaw(this, &FYourPlugin::MyExtender));
}
TSharedRef<FExtender> FYourPlugin::MyExtender(const TArray<FString>&Path)
{
// Extension variable contains a copy of selected paths array, you must keep Extension somewhere to prevent it from being deleted/garbage collected!
Extension = MakeShareable(new FContentBrowserMenuExtension(Path));
// Create extender that contains a delegate that will be called to get information about new context menu items
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
// Create a Shared-pointer delegate that keeps a weak reference to object
// "NewFolder" is a hook name that is used by extender to identify externders that will extend path context menu
MenuExtender->AddMenuExtension("NewFolder", EExtensionHook::After, TSharedPtr<FUICommandList>(),
FMenuExtensionDelegate::CreateSP(Extension.ToSharedRef(),
&FContentBrowserMenuExtension::AddMenuEntry));
return MenuExtender.ToSharedRef();
}
#define LOCTEXT_NAMESPACE "YourPlugin"
void FContentBrowserMenuExtension::AddMenuEntry(FMenuBuilder& MenuBuilder)
{
// Create Section
MenuBuilder.BeginSection("CustomMenu", LOCTEXT("PathViewOptionsMenuHeading", "Bulk Edit"));
{
// Create a Submenu inside of the Section
MenuBuilder.AddSubMenu(FText::FromString("Your Submenu"),
FText::FromString("Your Title"),
FNewMenuDelegate::CreateSP(this,&FContentBrowserMenuExtension::FillSubmenu));
}
MenuBuilder.EndSection();
}
void FContentBrowserMenuExtension::FillSubmenu(FMenuBuilder& MenuBuilder)
{
// Create the Submenu Entries
MenuBuilder.AddMenuEntry(
FText::FromString("Your Entry"),
FText::FromString("Your Entry"),
FSlateIcon(),
FUIAction(FExecuteAction::CreateSP(this, &FContentBrowserMenuExtension::OnYourMenuItemClicked))
);
}
void FContentBrowserMenuExtension::OnYourMenuItemClicked()
{
// Get selected path: this->Paths
// Do something
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_GAME_MODULE(FYourPlugin, YourPlugin);
Don’t forget to add public dependencies to Slate, ContentBrowser and other modules in YourPlugin.Build.cs
If you use AssetContextReferences instead of NewFolder and change MenuExtenderDelegates to not get the selected folder - it should work for asset context menues (like: