Skip to content

Instantly share code, notes, and snippets.

@brombres
Created August 12, 2023 13:49
Show Gist options
  • Save brombres/2e83dc407a41be7ca7feb1003775f950 to your computer and use it in GitHub Desktop.
Save brombres/2e83dc407a41be7ca7feb1003775f950 to your computer and use it in GitHub Desktop.
Skeleton to add a custom button to the Godot editor above the view.
# CustomEditorButton.gd
# Created 2023.08.12 by Brom Bresenham
@tool
extends EditorPlugin
var selected_object:Control
var button:Button
func _handles( object:Object )->bool:
return object is Control # or whatever type you want to handle
func _edit( object:Object ):
selected_object = object
func _make_visible( show:bool ):
if show:
button = Button.new()
button.flat = true
button.text = "Custom Button"
button.pressed.connect( on_button_pressed )
add_control_to_container( EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU, button )
elif button:
remove_control_from_container( EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU, button )
button.queue_free()
button = null
func on_button_pressed():
print("button pressed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment