Question about switching between multiple mouse cursor shapes

Godot Version



Hi! I’m trying to make a code that checks whether the current mouse cursor shape is 1 or 2 and changes it to the other one. So far I only got something like this:

func _unhandled_input(event):
if event.is_action_pressed(“Action1”):
if Input.get_current_cursor_shape()==cursor1:
Input.set_custom_mouse_cursor(cursor2, Input.CURSOR_ARROW, Vector2(0, 0))
Input.set_custom_mouse_cursor(cursor1, Input.CURSOR_ARROW, Vector2(0, 0))

3 things I don’t understand about this:

  1. Is it correct to use unhandled input or should I use the func _ready()?
  2. The part in bold, what do I write there (and anywhere else for that matter) to make the code work?
  3. The part in the last line that says ‘cursor1’, should it be “res://cursor1.png”? Because the debugging tool says the node is not found :man_shrugging:


Input.get_cursor_shape() returns the CursorShape, which corresponds with the second argument of Input.set_custom_mouse_cursor, which is in your case Input.CURSOR_ARROW.

You could try something along the idea of:

func _ready() -> void:
	var cursor1 = load("res://icon.svg")
	var cursor2 = load("res://icon.svg")
	Input.set_custom_mouse_cursor(cursor1, Input.CURSOR_ARROW, Vector2(10, 10))
	Input.set_custom_mouse_cursor(cursor2, Input.CURSOR_CROSS)

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("ui_accept"):
		if Input.get_current_cursor_shape() == Input.CURSOR_ARROW:

_ready is called only once, when the node enters the scene tree.
_unhandled_input is called whenever an InputEvent happens (and if it hasn’t been set to handled during the previous steps of input handling)


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.