Adding a Drop Down Menu
How to add our own Drop Down Menu
For Most Editor Menus
With a valid menu loaded, in most sections of the Editor we can use the following code to add our own dropdown menu:
ToolMenus= unreal.ToolMenus.get()
menu = ToolMenus.find_menu("LevelEditor.MainMenu")
dropdown_menu = menu.add_sub_menu(
owner="custom_owner", # this is used to delete menus later if needed
section_name="",
name="DemoTools",
label="Demo Tools"
)
ToolMenus.refresh_all_widgets()
This will add a new Demo Tools
entry to the top bar of the Editor:

The name
argument is used for the programmatic name, used for the menu path:
LevelEditor.MainMenu.DemoTools
The label
argument is what actually gets displayed in the UI
The owner
argument is useful for if we ever want to remove our menu:
ToolMenus.unregister_owner_by_name("custom_owner")
For ToolBar Menus (before 5.5)
For ToolBar Menus such as Sequencer, the above code does not work before UE 5.5. Instead, we need to create our own Toolbar Dropdown Menu Class and use it instead.
The Dropdown Class
This is using concepts covered in the Menu Class section, but here is a minimal class that will let us add a Dropdown Menu to Sequencer:
@unreal.uclass()
class ToolbarDropdownMenu(unreal.ToolMenuEntryScript):
"""Drop down menu class that can be used with Sequencer"""
def __init__(self, menu, name, label, section="", tooltip=""):
super().__init__()
self.data.advanced.entry_type = unreal.MultiBlockType.TOOL_BAR_COMBO_BUTTON
parent_menu = menu.get_editor_property("menu_name")
self.init_entry("custom_owner", parent_menu, section, name, label, tooltip)
menu.add_menu_entry_object(self)
They key to this class is that its entry_type
has been updated to TOOL_BAR_COMBO_BUTTON
. This will allow us to add it to Sequencer and other Tool Bars
Using Our Custom Class
With our ToolbarDropdownMenu class initialized, we can run the following to add our Dropdown Menu to Sequencer:
ToolMenus = unreal.ToolMenus.get()
menu = ToolMenus.find_menu("Sequencer.MainToolBar")
dropdown_menu = ToolbarDropdownMenu(
menu=menu,
name="DemoTools",
label="Demo Tools"
)
ToolMenus.refresh_all_widgets()
This will add a new Demo Tools
entry to Sequencer's Toolbar:

Last updated