How can I change the mouse cursor shape (over a control) immediately?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DrJosh9000

I have a Control. When the mouse cursor hovers over the Control it has the shape “Can Drop” (an open hand) that I configured with the inspector panel - so far so good. When the Control is clicked, I want the cursor to immediately change to to “Drag” (closed hand). And I’d like the reverse to happen immediately when the mouse button is released.

As far as I can tell, I can only change the cursor from script by calling set_default_cursor_shape(...). But it doesn’t seem to take effect until the mouse moves. It’s probably fine for now but I’d like the cursor shape to change right away. Is there some way to do that? Here’s my Control’s entire script:

extends Control

var start_mouse: Vector2
var start_pos: Vector2
var dragging = false

func _on_Item_gui_input(event):
	if event is InputEventMouseButton:
		dragging = event.pressed
		if dragging:
			start_pos = self.rect_position
			start_mouse = get_global_mouse_position()
			self.set_default_cursor_shape(Control.CURSOR_DRAG)
		else:
			self.set_default_cursor_shape(Control.CURSOR_CAN_DROP)
	elif event is InputEventMouseMotion:
		if dragging:
			self.set_position(get_global_mouse_position() - start_mouse + start_pos)

Open project settings, go to Display>Mouse Cursor. There should be Custom Image. That is where your image goes Custom image hotspot is your cursors detection point. The custom image must be less than 256x256.
This is from godot official docs and it worked for me.

perolegenda | 2022-04-11 16:31

Thanks perolegenda, but that didn’t help. I tried setting a custom image in the project settings as you suggested, but it doesn’t affect how quickly the cursor visibly changes when setting a cursor from a script - it still needs the mouse to move before it changes.

DrJosh9000 | 2022-04-11 23:06