How-To: Drag & Drop

Goal: drag an item from one widget and drop it on another, carrying a typed UObject payload.

Prerequisites
Source and target widgets. Drag-drop uses the standard UMG overrides (OnMouseButtonDown / OnDragDetected / OnDrop); CrimsonUI supplies the operation class.

1. Create the operation on drag

Screenshot pendingImages/CrimsonUI/howto-dragdrop-detect-bp.png
On Drag Detected override: Create Drag Drop Operation (Class = Crimson Drag Drop Operation) -> Set Payload Object (Payload = the item UObject) -> set Default Drag Visual -> return the operation.

2. Read the payload on drop

Screenshot pendingImages/CrimsonUI/howto-dragdrop-drop-bp.png
On Drop override: Cast To CrimsonDragDropOperation -> Get Payload Object -> Cast To your item class -> accept the item. Return true when handled.
Typed subclasses
Domain plugins subclass UCrimsonDragDropOperation and add strongly-typed properties (CrimsonCore's inventory does exactly this). SetPayloadObject / GetPayloadObject are both Blueprint-callable; GetPayload<T>() is the C++ typed shortcut.
Verify
Dragging shows your drag visual; dropping on the target delivers the exact UObject you set; dropping elsewhere cancels harmlessly.

See also

  • How-To: Lists with Mixed Item Types - the entries you usually drag.