If anyone can remember UO (Ultimate Online) I have a spell book, with spells. I want to drag a spell widget(copy) from the book unto the HUD. So the user can click(Highlight the spell) and is ready to cast. The player can place dozen of spells all over the HUD. Instead of in the hotbar. They can remove the Widget spell now on the HUD by simply deleting it. or move it into another position.
I have looked at dozen of tutorials and all they have is dragging a widget around the HUD. IE: just moving it around.
Does anyone know how and example or know of a tutorial of this exact thing I wish to do.
You can do this with UMG’s drag-and-drop pair of overrides rather than only moving a widget around the HUD.
In the spell widget (the one in the book), override OnMouseButtonDown: call “Detect Drag If Pressed” with the Left Mouse Button key and return the Handled result.
Override OnDragDetected: use “Create Widget” to make a new instance of the spell widget (or a lighter icon-only widget), then “Create Drag Drop Operation” (class DragDropOperation). Set its Payload (add a variable like SpellID on a custom DragDropOperation subclass) and set Default Drag Visual to the new widget. Output the operation.
On the HUD root widget (needs a Canvas Panel as its base and Visibility not set to Hit-Test Invisible), override OnDrop. Cast the operation to your custom class, create the spell widget, and “Add Child to Canvas”, then set its position from “Get Screen Space Position” / “Absolute to Local” using MyGeometry and the PointerEvent screen position.
To move a placed widget later, make the placed widget also start a drag, but remove it from its parent first. To delete it, drop it on a trash zone or add a right-click handler that calls Remove From Parent.
The key point is that dragging creates a copy as the payload, while OnDrop on the HUD is what actually spawns it at the cursor position.
On the HUD root widget (needs a Canvas Panel as its base and Visibility not set to Hit-Test Invisible), override OnDrop. "Cast the operation to your custom class", create the spell widget, and “Add Child to Canvas”, then set its position from “Get Screen Space Position” / “Absolute to Local” using MyGeometry and the PointerEvent screen position.