How to prevent Drag and Drop operation on self

I have a widget set up with a drag and drop operation. When the drag is detected I set the visibility of the original widget to “Hidden” so that all you see is the widget you’re dragging (I think this looks cleaner than dragging a transparent version of the widget).

When I drop the widget into my main widget encompassing the screen, it works just dandy. I have my OnDrop configured there to set the widget position and set visibility.

But if move the widget a tiny bit and drop it the drop is actually detected on the (hidden) widget being dragged. If I override the OnDrop for my widget I can detect that it has been dropped on “itself”. I could copy/paste all the code from my main widget as well to move the position and set visibility but I hate the idea of having to plop this code in every place the user could drag the widget. I thought by returning false in the OnDrop UE4 might say “Ok, this widget didn’t handle the drop - let’s look to the next widget down to see if IT will handle it”. But it turns out the Drag and Drop operation is ended regardless of if it is handled which I think is a bit silly.

Is there any cleaner way to handle this other than copy/pasting code everywhere?

Edit: And it seems copy/pasting code everywhere isn’t even as easy as I’d thought - it calculates the drop position incorrectly and the widget kinda just vanishes…

I found a better way to handle this. I bound an event to my drag and drop operation to detect when the operation has been dropped or canceled and I set my visibility based on that instead of relying on the dropped-on widget to handle updating the visibility.

1 Like