Cancel an ongoing Drag-and-Drop

Godot Version

v4.3.stable.official.77dcf97d8

Question

On a key press, the user toggle a UI where drag-and-drop is possible.
When he close back the UI, I want the dragging operation to stop, if one was ongoing.

I tried using Viewport.force_drag, or calling Control._drop_data myself but even if it worked (which it doesn’t) it seems like a very bad solution.

You can redrag it to where it was before dragging it.

That’s what I tried using Viewport.force_drag, but I didn’t succeed.
How would you do that ?

Recently the function Viewport.gui_cancel_drag() was introduced. It is available since Godot 4.4-dev2. I don’t see an easy and reliable way to cancel drag in Godot 4.3.

2 Likes