Add a custom button to the unreal editor Level Editor Toolbar; Part 2
Tue Nov 08 2022 14:08:19 GMT+0000 (UTC)
Saved by
@MaVCArt
#python
# -- now we tell unreal that the button we just created is ACTUALLY a menu.
# -- this makes it so that when pressed, unreal does not invoke the button's "actions",
# -- but instead creates a context menu we can populate.
# -- calling this "register_menu" function helpfully also returns a handle on the menu object itself.
# -- Note how we have to register the button by its Name property.
sub_menu = tool_menus.register_menu(
# the menu name -- this MUST MATCH the name of the combo button we gave
'LevelEditor.LevelEditorToolBar.MyPythonMenu',
# parent - we leave this blank in this case
'',
# menu type - we just want a normal menu
unreal.MultiBoxType.MENU,
# warn_if_already_registered - if False, this will just not do anything if it already exists.
False
)
# -- now we can create a menu entry. This can be done in a variety of ways.
menu_entry = unreal.ToolMenuEntry()
menu_entry.name = 'MyCustomOption'
menu_entry.set_label('My Custom Option')
menu_entry.type = unreal.MultiBlockType.MENU_ENTRY
sub_menu.add_menu_entry('My Custom Section', menu_entry)
# -- as a final step we need to tell unreal to refresh all menus
tool_menus.refresh_all_widgets()
content_copyCOPY
Comments