Add a custom button to the unreal editor Level Editor Toolbar; Part 2


Tue Nov 08 2022 14:08:19 GMT+0000 (Coordinated Universal Time)

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
    # parent - we leave this blank in this case
    # menu type - we just want a normal menu
    # warn_if_already_registered - if False, this will just not do anything if it already exists.

# -- now we can create a menu entry. This can be done in a variety of ways.
menu_entry = unreal.ToolMenuEntry() = '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