Skip to content

Drag & Drop System

DragDropSystem is an Autoload that handles all mouse interactions for moving items between slots, splitting stacks, and dropping items into the 3D world.

Mouse Controls

Drag & Drop

  • Left Click (Hold & Drag): Picks up the entire stack.
  • Right Click (Hold & Drag): Picks up exactly half the stack.
  • While dragging a right-click stack: Right-click again to drop exactly 1 item.
  • Scroll Wheel (While Dragging): Dynamically adjusts the drag_amount up or down.

Quick Move (New!)

  • Shift + Left Click: Instantly transfers the entire stack to another open inventory.
  • Right Click (No Drag): Transfers a single item to another open inventory.

Quick Move Behavior

Quick move only works when two inventory panels are open simultaneously (e.g., player inventory + chest). System automatically finds the other visible panel and transfers items to it.

Drop Targets

For a UI Control to receive dropped items, it must meet two requirements:

  1. Be in the inventory_drop_targets group.
  2. Have two metadata properties set:
  3. "inventory": Inventory resource reference.
  4. "slot_index": integer index of the slot.

SlotUI script handles this automatically when instantiated by the inventory panels.

Dropping to the 3D World

If you drag an item outside of any valid UI drop target and release the mouse, DragDropSystem will drop the item into the 3D world.

  • It finds the player node (via the "player" group or the first CharacterBody3D).
  • Spawns the DroppedItem scene 1.5 units in front of the player.
  • Applies a random physics impulse so the item tumbles realistically.

InventoryTransfer (Static Helper)

InventoryTransfer class contains the logic of moving items between inventories.

  • transfer(): Moves items from source to target, automatically finding empty slots or stacking onto existing items.
  • drop_to_slot(): Handles direct slot-to-slot drops. It can exchange items when one is dragged onto another items (if you drag a sword onto a shield, they swap places, provided both slots' rules allow it).
  • quick_move(): A backend helper method to instantly move an entire stack from one inventory to another.

No Default UI Binding

quick_move() method exists in the backend, but the default UI components (ModularInventoryPanel, ModularHotbar, SlotUI) do not include input bindings for Shift-click or double-click to trigger this method.