Skip to content

Instantly share code, notes, and snippets.

@ed-lynn
Created February 9, 2025 07:27
Show Gist options
  • Save ed-lynn/0e3e4aa6dde8f3aa894352ffe8fd882d to your computer and use it in GitHub Desktop.
Save ed-lynn/0e3e4aa6dde8f3aa894352ffe8fd882d to your computer and use it in GitHub Desktop.
import unreal
def on_button_clicked():
unreal.log("Custom Editor Button Clicked!")
def add_custom_toolbar_button():
editor_utility_subsystem = unreal.get_editor_subsystem(unreal.EditorUtilitySubsystem)
if not editor_utility_subsystem:
unreal.log_warning("Failed to get EditorUtilitySubsystem!")
return
tool_menus = unreal.ToolMenus.get()
toolbar_menu = tool_menus.extend_menu("LevelEditor.MainToolBar")
entry = unreal.ToolMenuEntry(
name="CustomButton",
type=unreal.MultiBlockType.TOOL_BAR_BUTTON,
insert_position=unreal.ToolMenuInsert("Settings", unreal.ToolMenuInsertType.AFTER)
)
entry.set_label("My Button")
entry.set_tool_tip("Click to run custom action")
entry.set_icon("EditorStyle", "Icons.Toolbar.Settings")
entry.set_string_command(unreal.ToolMenuStringCommand(
type=unreal.ToolMenuStringCommandType.PYTHON,
custom_type="",
string="on_button_clicked()"
))
toolbar_menu.add_menu_entry("CustomSection", entry)
tool_menus.refresh_all_widgets()
unreal.log("Custom toolbar button added!")
# Run the function to add the button
add_custom_toolbar_button()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment