Widget drag and drop is always to the left corner

Every time I drag a widget, it goes locked to the left corner.

Can’t seem to fix it, even when following this steps:

Anyone an idea?

Doubt anyone can help without seeing the script and the dragged widget hierarchy.

This is the Widget blueprint: inventoryWindow:

With OnMouseButtonDown function override:

And OnDragDetected function override:

Main HUD:

With OnDrop function override:

I have a BP_DemoDragDrop with native parent class: UMG.DragDropOperation with these values:


In viewport:

I’ll have a closer look tomorrow. At a glance - the hierarchy of the dragged widget is not correct because it’s sitting in a canvas and not doing anything. This may offset things, maybe.

Also, could you briefly describe how it’s supposed to work. Initially i thought we’d be dragging something into an inventory, but here we drag the inventory windows themselves? Right? If so, what are we dropping on, the Main Hud?


Meanwhile, while you wait, have a look here, perhaps it will inspire you:

Seems very close to the setup you need. It does not utilise drag & drop (because it’s not really required here) but comes with zOrdering.

Yes, the main goal is just to drag the inventory widget itself across the screen and dropping it into the main HUD.

A player can toggle the Inventory widget visibility with “I” and can drag it across the screen (Main HUD).

I also tried it without the canvas, but result is still the same.

But here you’re placing it in the viewport instead, ignoring the main hud completely:

You need to make a choice:

  • if you want the widgets to sit directly in the viewport, do not use a Main Hud with a canvas - it defeats the purpose. Above, the dragged widget is actually removed from its Main Hud canvas… Probably the last thing you wanted.
  • if you want to have a MainHud hosting widgets (a highly recommended approach, and a logical choice for what’s at hand here), use said canvas:

A widget that’s already living happily in the canvas does not need to be re-parented (remove & add). Just ensure the canvas is set to be Visible so we have something to drop it on.


Apart from that, while using drag & drop may work for this, it seems unnecessary unless you need to run-time place containers inside containers inside containers…

Consider the onMouseMove method linked above, much more friendly and flexible. At least for moving windows around in the same layer. You’d use drag & drop if you wanted a widget to change a parent container. Here they all stay in the same one.

while using drag & drop may work for this[…]

And it does:

  • the main hud with canvas made Visible:

  • the draggable widget windows:

image

If you’re having issues with this not dropping sometimes, it’s probably due to it dropping on itself. The original widget should be hidden or made not hit-testable when the drag occurs.


My gut feeling tells me this is not the right tool for the job. Hope it serves you well, though!

Good luck!

Thank you for your explanation! Because of you I have better knowledge now about handling widgets.

I managed to get it working thanks to your explanation and info.
Thank you very much for putting time and effort in helping me!

1 Like