Saturday, October 25, 2025

Godot Resources: Custom Cursors

    This recipe presents a way to use custom resources in Godot to enable multiple custom mouse cursors and even switching between sets of cursors. The assumption is that the reader knows how to do some actions in Godot, like making custom scripts, and some programing concepts, like for loops. Written for Godot 4.5.stable.official.

Use Cases / Why?

- Professional appearance

- Cohesive style aids immersion 

- Accessibility

New Resource: 

class_name CustomMouse extends Resource

@export var cursor_type: Input.CursorShape
@export var icon: Texture
@export var offset := Vector2.ZERO

func activate() -> void:
    if icon:
        Input.set_custom_mouse_cursor(
            icon, 
            cursor_type, 
            offset
        )

func apply_to(node: Control) -> void:
    node.set_default_cursor_shape(cursor_type as Control.CursorShape)

 

Script in game root:

@export var custom_cursors: Array[CustomMouse]

func _ready() -> void:
    for each in custom_cursors:
        each.activate()

Example of how the Array[CustomMouse] looks in the Engine Scene: 


Script that extends any Control node:

@export var mouse_cursor: CustomMouse

func _ready() -> void:
    if mouse_cursor:
        mouse_cursor.apply_to(self) 

Godot Documentation:

https://docs.godotengine.org/en/4.5/classes/class_input.html#class-input-method-set-custom-mouse-cursor

https://docs.godotengine.org/en/4.5/classes/class_control.html#class-control-property-mouse-default-cursor-shape