Extend Content Browser context menu

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:

FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");

TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
		MenuExtender->AddMenuExtension("WindowLayout", EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FItemsDBManagerModule::AddMenuExtension));

		LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);

But to extend the Content Browser I was looking for something exactly like this:

FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
AssetContextReferenceExtender->AddMenuExtension("AssetContextReferences", EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FItemsDBManagerModule::AddSelectPickupAssetExtension));
ContentBrowserModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender); //This doesn't exist

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! :slight_smile:

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.

This is where I’m stuck as well, though on 4.23.

It’s a delegate, bind function to it:

I have done this quite a while ago - not sure if it is still compatible with recent UE Versions. Give it a try :wink:

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:

TArray<FContentBrowserMenuExtender_SelectedPaths>& MenuExtenderDelegates = ContentBrowserModule.GetAllPathViewContextMenuExtenders();

becomes something like =>

TArray<FContentBrowserMenuExtender_SelectedAssets>& MenuExtenderDelegates = ContentBrowserModule.GetAllAssetViewViewMenuExtenders();
1 Like