Set Mouse Cursor in Editor for Plugins

Godot Version

4.3

Question

I’m right now writing an interactive plugin for Godot. The user is able to drag some items around in the editor main viewport, basically a 2D gizmo. I want to update the cursor so that the user knows they can drag these items around. However, it seems Input.set_custom_mouse_cursor is only for in-game? Is there an editor plugin equivalent.

Thank you!
Nate

3 Likes

You can control the in editor cursor by overriding the _forward_canvas_draw_over_viewport method in your EditorPlugin script, and setting the mouse_default_cursor_shape property on the viewport control, to your desired cursor shape,.

Below is a code snippet which changes the cursor to a dragging cursor, whenever _forward_canvas_draw_over_viewport is called.

@tool
extends EditorPlugin

func _handles(o: Object) -> bool:
    # return true when you want to control cursor shape.
    # in this scenario, the cursor is controlled for all object types.    
    return true

func _forward_canvas_gui_input(e: InputEvent) -> bool:
    # force _forward_canvas_draw_over_viewport call anytime an input event is received.
    update_overlays()
    return false

func _forward_canvas_draw_over_viewport(viewport_control: Control) -> void:
    # Set cursor shape here
    viewport_control.mouse_default_cursor_shape = Control.CURSOR_DRAG
1 Like