Skip to content

Draggable Nodes

Valk edited this page Oct 4, 2024 · 10 revisions

Important

Area2D's are not only created for Node2D's but also for Control nodes. This can be seen as extra unwanted bloat. This may be fixed in the future so only Area2D's are created for Node2D's and the Guiinput event is used for Control nodes. This is not being tracked in any issue as of writing this.

Simply add the [Draggable] attribute and implement IDraggable for any Node2D or Control node and it will become draggable in-game.

using Godot;

// Hold to drag and limit movement to vertical axis
[Draggable(DragType.Hold, DragConstraints.Vertical)]
public partial class DraggableNode : Node2D, IDraggable
{
    public void OnDragReleased()
    {
        // Do something with DraggableNode here!
        // If the node is not re-parented or queue freed, it will snap back to its original position and parent
    }
}
Clone this wiki locally