Drop widget as a child of existing widget

Hi,

I was following the Unreal documentation to drag and drop widget in my viewport but I’m stuck with this problem:

When I drop my widget inside another widget, it creates a “new” viewport, and it’s not a child anymore.

This is the on drop function.

as you can see in the widget reflector, I want the wb_Victory inside the wb hud where it was before the drag&drop operation. I can’t find a solution.

Any help?

p.s. this does not work

Why are you removing the widget from its parent if it’s already inside wb_hud? Just leave it where it is. Remove all the RemoveFromParent and AddToViewport nodes and just move the widget to where it’s supposed to go.

Now, if the drag operation changes the parent during the dragging, then you’d need to store the original parent before it is changed so you can restore it during the OnDrop function. But you still wouldn’t call AddToViewport.

I was tryiing to recreate what I tried before doing the post and I forgot to leave those functions there, buy I already tried with this

The widget doesn’t move at all and go back to the original place, even if the position value is changing correctly and the widget reference is correct

I’m reading that the SetPositionInViewport node was changed in 5.1 to only work on top level widgets that were added directly to the viewport. Said plainly, if the widget you are trying to move is already in a container, SetPositionInViewport does nothing.

What does work if it’s in a canvas is this:

ChildWidget→SlotAsCanvasSlot→SetPosition

edit: I think SetPosition here is relative to the container. So you’ll have to translate or add the offset (and convert the offset to local coordinates) to the local coordinates, not global ones.

Thanks for the help:

This works!