Why force_drag doesn't work

Godot Version

v4.2.2.stable.mono.official [15073afe3]

Question

I have a button with these code:

func _on_pressed() -> void:
	force_drag(self,duplicate())

func _gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			force_drag(self,duplicate())
			print("我已被点击 D:%s" % name)
			accept_event()

the force_drag work perfect if i use ‘_on_pressed’ , and when i change to ‘_gui_input’ , it doesn’t work , i don’t know why . can some one help me , thank you! :heart:

Looks like an engine bug. It may be this part godot/scene/main/viewport.cpp at 3504c98c1233bbd2506e89ce46509bc79afaec17 · godotengine/godot · GitHub I’m not 100% sure.

The _gui_input() is processed a few lines above, it will force the drag so gui.dragging will be true and the mouse button index is also left so it immediately drops the drag data.

Please open an issue here Issues · godotengine/godot · GitHub filling the Bug report form.

1 Like

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