Up to date
This page is up to date for Godot 4.0
.
If you still find outdated information, please open an issue.
EditorPlugin¶
Used by the editor to extend its functionality.
Description¶
Plugins are used by the editor to extend functionality. The most common types of plugins are those which edit a given node or resource type, import plugins and export plugins. See also EditorScript to add functions to the editor.
Tutorials¶
Methods¶
Signals¶
main_screen_changed ( String screen_name )
Emitted when user changes the workspace (2D, 3D, Script, AssetLib). Also works with custom screens defined by plugins.
project_settings_changed ( )
Emitted when any project setting has changed.
resource_saved ( Resource resource )
Emitted when the given resource
was saved on disc.
scene_changed ( Node scene_root )
Emitted when the scene is changed in the editor. The argument will return the root node of the scene that has just become active. If this scene is new and empty, the argument will be null
.
scene_closed ( String filepath )
Emitted when user closes a scene. The argument is file path to a closed scene.
Enumerations¶
enum CustomControlContainer:
CustomControlContainer CONTAINER_TOOLBAR = 0
Main editor toolbar, next to play buttons.
The toolbar that appears when 3D editor is active.
CustomControlContainer CONTAINER_SPATIAL_EDITOR_SIDE_LEFT = 2
Left sidebar of the 3D editor.
CustomControlContainer CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT = 3
Right sidebar of the 3D editor.
CustomControlContainer CONTAINER_SPATIAL_EDITOR_BOTTOM = 4
Bottom panel of the 3D editor.
The toolbar that appears when 2D editor is active.
CustomControlContainer CONTAINER_CANVAS_EDITOR_SIDE_LEFT = 6
Left sidebar of the 2D editor.
CustomControlContainer CONTAINER_CANVAS_EDITOR_SIDE_RIGHT = 7
Right sidebar of the 2D editor.
CustomControlContainer CONTAINER_CANVAS_EDITOR_BOTTOM = 8
Bottom panel of the 2D editor.
CustomControlContainer CONTAINER_INSPECTOR_BOTTOM = 9
Bottom section of the inspector.
CustomControlContainer CONTAINER_PROJECT_SETTING_TAB_LEFT = 10
Tab of Project Settings dialog, to the left of other tabs.
CustomControlContainer CONTAINER_PROJECT_SETTING_TAB_RIGHT = 11
Tab of Project Settings dialog, to the right of other tabs.
enum DockSlot:
DockSlot DOCK_SLOT_LEFT_UL = 0
Dock slot, left side, upper-left (empty in default layout).
DockSlot DOCK_SLOT_LEFT_BL = 1
Dock slot, left side, bottom-left (empty in default layout).
DockSlot DOCK_SLOT_LEFT_UR = 2
Dock slot, left side, upper-right (in default layout includes Scene and Import docks).
DockSlot DOCK_SLOT_LEFT_BR = 3
Dock slot, left side, bottom-right (in default layout includes FileSystem dock).
DockSlot DOCK_SLOT_RIGHT_UL = 4
Dock slot, right side, upper-left (empty in default layout).
DockSlot DOCK_SLOT_RIGHT_BL = 5
Dock slot, right side, bottom-left (empty in default layout).
DockSlot DOCK_SLOT_RIGHT_UR = 6
Dock slot, right side, upper-right (in default layout includes Inspector, Node and History docks).
DockSlot DOCK_SLOT_RIGHT_BR = 7
Dock slot, right side, bottom-right (empty in default layout).
DockSlot DOCK_SLOT_MAX = 8
Represents the size of the DockSlot enum.
enum AfterGUIInput:
AfterGUIInput AFTER_GUI_INPUT_PASS = 0
Forwards the InputEvent to other EditorPlugins.
AfterGUIInput AFTER_GUI_INPUT_STOP = 1
Prevents the InputEvent from reaching other Editor classes.
AfterGUIInput AFTER_GUI_INPUT_CUSTOM = 2
Pass the InputEvent to other editor plugins except the main Node3D one. This can be used to prevent node selection changes and work with sub-gizmos instead.
Method Descriptions¶
void _apply_changes ( ) virtual
This method is called when the editor is about to save the project, switch to another tab, etc. It asks the plugin to apply any pending state changes to ensure consistency.
This is used, for example, in shader editors to let the plugin know that it must apply the shader code being written by the user to the object.
bool _build ( ) virtual
This method is called when the editor is about to run the project. The plugin can then perform required operations before the project runs.
This method must return a boolean. If this method returns false
, the project will not run. The run is aborted immediately, so this also prevents all other plugins' _build methods from running.
void _clear ( ) virtual
Clear all the state and reset the object being edited to zero. This ensures your plugin does not keep editing a currently existing node, or a node from the wrong scene.
void _disable_plugin ( ) virtual
Called by the engine when the user disables the EditorPlugin in the Plugin tab of the project settings window.
void _edit ( Object object ) virtual
This function is used for plugins that edit specific object types (nodes or resources). It requests the editor to edit the given object.
object
can be null
if the plugin was editing an object, but there is no longer any selected object handled by this plugin. It can be used to cleanup editing state.
void _enable_plugin ( ) virtual
Called by the engine when the user enables the EditorPlugin in the Plugin tab of the project settings window.
void _forward_3d_draw_over_viewport ( Control viewport_control ) virtual
Called by the engine when the 3D editor's viewport is updated. Use the overlay
Control for drawing. You can update the viewport manually by calling update_overlays.
func _forward_3d_draw_over_viewport(overlay):
# Draw a circle at cursor position.
overlay.draw_circle(overlay.get_local_mouse_position(), 64)
func _forward_3d_gui_input(camera, event):
if event is InputEventMouseMotion:
# Redraw viewport when cursor is moved.
update_overlays()
return EditorPlugin.AFTER_GUI_INPUT_STOP
return EditorPlugin.AFTER_GUI_INPUT_PASS
public override void _Forward3DDrawOverViewport(Control viewportControl)
{
// Draw a circle at cursor position.
viewportControl.DrawCircle(viewportControl.GetLocalMousePosition(), 64, Colors.White);
}
public override EditorPlugin.AfterGuiInput _Forward3DGuiInput(Camera3D viewportCamera, InputEvent @event)
{
if (@event is InputEventMouseMotion)
{
// Redraw viewport when cursor is moved.
UpdateOverlays();
return EditorPlugin.AfterGuiInput.Stop;
}
return EditorPlugin.AfterGuiInput.Pass;
}
void _forward_3d_force_draw_over_viewport ( Control viewport_control ) virtual
This method is the same as _forward_3d_draw_over_viewport, except it draws on top of everything. Useful when you need an extra layer that shows over anything else.
You need to enable calling of this method by using set_force_draw_over_forwarding_enabled.
int _forward_3d_gui_input ( Camera3D viewport_camera, InputEvent event ) virtual
Called when there is a root node in the current edited scene, _handles is implemented, and an InputEvent happens in the 3D viewport. The return value decides whether the InputEvent is consumed or forwarded to other EditorPlugins. See AfterGUIInput for options.
Example:
# Prevents the InputEvent from reaching other Editor classes.
func _forward_3d_gui_input(camera, event):
return EditorPlugin.AFTER_GUI_INPUT_STOP
// Prevents the InputEvent from reaching other Editor classes.
public override EditorPlugin.AfterGuiInput _Forward3DGuiInput(Camera3D camera, InputEvent @event)
{
return EditorPlugin.AfterGuiInput.Stop;
}
Must return EditorPlugin.AFTER_GUI_INPUT_PASS
in order to forward the InputEvent to other Editor classes.
Example:
# Consumes InputEventMouseMotion and forwards other InputEvent types.
func _forward_3d_gui_input(camera, event):
return EditorPlugin.AFTER_GUI_INPUT_STOP if event is InputEventMouseMotion else EditorPlugin.AFTER_GUI_INPUT_PASS
// Consumes InputEventMouseMotion and forwards other InputEvent types.
public override EditorPlugin.AfterGuiInput _Forward3DGuiInput(Camera3D camera, InputEvent @event)
{
return @event is InputEventMouseMotion ? EditorPlugin.AfterGuiInput.Stop : EditorPlugin.AfterGuiInput.Pass;
}
void _forward_canvas_draw_over_viewport ( Control viewport_control ) virtual
Called by the engine when the 2D editor's viewport is updated. Use the overlay
Control for drawing. You can update the viewport manually by calling update_overlays.
func _forward_canvas_draw_over_viewport(overlay):
# Draw a circle at cursor position.
overlay.draw_circle(overlay.get_local_mouse_position(), 64, Color.WHITE)
func _forward_canvas_gui_input(event):
if event is InputEventMouseMotion:
# Redraw viewport when cursor is moved.
update_overlays()
return true
return false
public override void _ForwardCanvasDrawOverViewport(Control viewportControl)
{
// Draw a circle at cursor position.
viewportControl.DrawCircle(viewportControl.GetLocalMousePosition(), 64, Colors.White);
}
public override bool _ForwardCanvasGuiInput(InputEvent @event)
{
if (@event is InputEventMouseMotion)
{
// Redraw viewport when cursor is moved.
UpdateOverlays();
return true;
}
return false;
}
void _forward_canvas_force_draw_over_viewport ( Control viewport_control ) virtual
This method is the same as _forward_canvas_draw_over_viewport, except it draws on top of everything. Useful when you need an extra layer that shows over anything else.
You need to enable calling of this method by using set_force_draw_over_forwarding_enabled.
bool _forward_canvas_gui_input ( InputEvent event ) virtual
Called when there is a root node in the current edited scene, _handles is implemented and an InputEvent happens in the 2D viewport. Intercepts the InputEvent, if return true
EditorPlugin consumes the event
, otherwise forwards event
to other Editor classes.
Example:
# Prevents the InputEvent from reaching other Editor classes.
func _forward_canvas_gui_input(event):
return true
// Prevents the InputEvent from reaching other Editor classes.
public override bool ForwardCanvasGuiInput(InputEvent @event)
{
return true;
}
Must return false
in order to forward the InputEvent to other Editor classes.
Example:
# Consumes InputEventMouseMotion and forwards other InputEvent types.
func _forward_canvas_gui_input(event):
if (event is InputEventMouseMotion):
return true
return false
// Consumes InputEventMouseMotion and forwards other InputEvent types.
public override bool _ForwardCanvasGuiInput(InputEvent @event)
{
if (@event is InputEventMouseMotion)
{
return true;
}
return false;
}
PackedStringArray _get_breakpoints ( ) virtual const
This is for editors that edit script-based objects. You can return a list of breakpoints in the format (script:line
), for example: res://path_to_script.gd:25
.
Texture2D _get_plugin_icon ( ) virtual const
Override this method in your plugin to return a Texture2D in order to give it an icon.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", and "AssetLib" buttons.
Ideally, the plugin icon should be white with a transparent background and 16x16 pixels in size.
func _get_plugin_icon():
# You can use a custom icon:
return preload("res://addons/my_plugin/my_plugin_icon.svg")
# Or use a built-in icon:
return get_editor_interface().get_base_control().get_theme_icon("Node", "EditorIcons")
public override Texture2D _GetPluginIcon()
{
// You can use a custom icon:
return ResourceLoader.Load<Texture2D>("res://addons/my_plugin/my_plugin_icon.svg");
// Or use a built-in icon:
return GetEditorInterface().GetBaseControl().GetThemeIcon("Node", "EditorIcons");
}
String _get_plugin_name ( ) virtual const
Override this method in your plugin to provide the name of the plugin when displayed in the Godot editor.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", and "AssetLib" buttons.
Dictionary _get_state ( ) virtual const
Override this method to provide a state data you want to be saved, like view position, grid settings, folding, etc. This is used when saving the scene (so state is kept when opening it again) and for switching tabs (so state can be restored when the tab returns). This data is automatically saved for each scene in an editstate
file in the editor metadata folder. If you want to store global (scene-independent) editor data for your plugin, you can use _get_window_layout instead.
Use _set_state to restore your saved state.
Note: This method should not be used to save important settings that should persist with the project.
Note: You must implement _get_plugin_name for the state to be stored and restored correctly.
func _get_state():
var state = {"zoom": zoom, "preferred_color": my_color}
return state
void _get_window_layout ( ConfigFile configuration ) virtual
Override this method to provide the GUI layout of the plugin or any other data you want to be stored. This is used to save the project's editor layout when queue_save_layout is called or the editor layout was changed (for example changing the position of a dock). The data is stored in the editor_layout.cfg
file in the editor metadata directory.
Use _set_window_layout to restore your saved layout.
func _get_window_layout(configuration):
configuration.set_value("MyPlugin", "window_position", $Window.position)
configuration.set_value("MyPlugin", "icon_color", $Icon.modulate)
bool _handles ( Object object ) virtual const
Implement this function if your plugin edits a specific type of object (Resource or Node). If you return true
, then you will get the functions _edit and _make_visible called when the editor requests them. If you have declared the methods _forward_canvas_gui_input and _forward_3d_gui_input these will be called too.
bool _has_main_screen ( ) virtual const
Returns true
if this is a main screen editor plugin (it goes in the workspace selector together with 2D, 3D, Script and AssetLib).
When the plugin's workspace is selected, other main screen plugins will be hidden, but your plugin will not appear automatically. It needs to be added as a child of