This sample demonstrates how you could Drag & Drop items from a Control
node, to either another Control
or onto a Node2D
(via a SubViewport
).
Be warned! This repository:
- Was created while learning Godot 4, and is not "expert advice";
- Will likely not be kept up to date;
- Might have differences for Godot 3.x and earlier;
Still, it might help someone!
This is what it should do:
I found this Question without any answer, and wanted the same thing. I'm a beginner with Godot but still came up with something that works, not sure if it would hold up or is proper. Disclaimers out of the way, here's my solution.
The essence of the repository linked above is:
- Encapsulate the
Node2D
stuff in aSubViewport
node that's again a child of aSubViewportContainer
node; - Implement the
_drop_data(...)
function on theSubViewportcontainer
; - Make it "drop" the actual stuff as a child of the
Node2D
stuff
See the various scripts for how this works:
item.gd
: for the start of Drag & Drop operationsdrop_zone_sub_viewport_container.gd
: for the Drop part onto aNode2D
target, via aSubViewportContainer
drop_zone_control_node.gd
: for the Drop part onto aControl
target