I'd been following Godot tutorials to add Drag & Drop functionality to Control
nodes. They've presumably been created for Godot 3.x, but my project is 4.0. And I can't seem to get it to work, thinking something has changed.
To make sure it's due to the difference in Godot versions, I did the exact same steps to reproduce the situation in both Godot 4.0 and 3.5.1:
Create new project, all default settings
Add
Node2D
root sceneAdd a
PanelContainer
child to thatAdd a
TextureRect
child to that, and drag the Godot icon resource on it for testingAttach a new script to
PanelContainer
with this code:extends PanelContainer func get_drag_data(_position): var preview = TextureRect.new() preview.texture = $TextureRect.texture set_drag_preview(preview) return { id = "foobar" }
Run the game
The results:
- In 3.5.1, as expected, you can drag around the Godot icon;
- In 4.0, nothing happens, dragging the icon around won't work;
What am I missing? How to get dragging of nodes working in version 4.x?
I've tried a few extra things to answer my own question:
- Search the web, but at the time of writing it seems to give results that are 3.x-specific;
- Go through the node's "Inspector" properties, especially
Mouse
properties