Unreal allows you to extend the new assets menu via Slate. This makes it fairly straightforward to add custom submenus or other things into it.
Note: The default submenus and assets shown are controlled through UFactory and some related classes. For completely custom asset types, you can create a new factory and add it into the menu through that mechanism also.
Plugin
I’ve created a plugin which allows you to configure additional items into the New Asset menu from Project Settings - Check zomg’s editor addons if you’re interested - No C++ code required.
Manual setup
Creating a submenu
This code would typically be triggered from an editor plugin’s StartupModule or some similar location.
Side note: There are many menus in the editor which can be customized using this approach. See How to find ToolMenu names for how to find the menu names used for this.
//This gives us access to the menu for extension purposes.
//There are some other menus which can be customized via this mechanism also.
UToolMenu* Menu = UToolMenus::Get()->ExtendMenu("ContentBrowser.AddNewContextMenu");
//This creates a new "section" with the given label into the menu
FToolMenuSection& Section = Menu->AddSection("SectionInternalName", INVTEXT("Section Display Name"));
auto SubmenuDelegate = FNewToolMenuDelegate::CreateLambda([CanExecuteAssetActionsDelegate, Factories, MenuSettings](UToolMenu* Menu)
{
FToolMenuSection& SubSection = Menu->FindOrAddSection("Section");
SubSection.AddEntry(FToolMenuEntry::InitMenuEntry(
NAME_None,
FUIAction(
FExecuteAction::CreateLambda([]()
{
//This code will run when the submenu item is clicked
}),
//You can pass in a delegate which is used to test if the
//submenu action should be allowed to execute
FCanExecuteAction()
),
//Slate content for the new menu item
SNew(STextBlock).Text(INVTEXT("Hello"))
));
}
});
Section.AddSubMenu(
FName("MenuReferenceName"),
INVTEXT("Menu Display Name"),
//Tooltip
FText::GetEmpty(),
//This delegate is used to create the submenu
SubmenuDelegate,
//This can be used to trigger a specific action from this submenu item
//or control when this submenu is enabled via the FCanExecuteAction delegate
FUIAction(FExecuteAction(), FCanExecuteAction()),
EUserInterfaceActionType::Button
);
The Menu
object allows you to do various customizations of the new assets menu. The code here adds a new named section into it, and adds a new submenu under the new section, with one entry.
You can provide any kind of Slate content you wish in the menu.
You can clean up menu modifications such as in a module’s ShutdownModule
function via:
if(auto* ToolMenus = UToolMenus::Get())
{
if(UToolMenu* Menu = ToolMenus->ExtendMenu("ContentBrowser.AddNewContextMenu"))
{
Menu->RemoveSection("MenusFNameGoesHere");
}
}