I followed Drag and Drop with UMG, Part 1 on YouTUbe, thanks. I’m stuck on the widget to drag being created at the origin 0,0 and if the pivot is center, center it animates to dragging center. If the pivot is mouse down it starts at 0, 0 and drags form there, so the mouse has a big offset from it. I want the center, center effect once dragging, but I don’t want it to fly from 0, 0 to the mouse pointer. Here are my mouse down and mouse drag detect. Thanks for any help.
To answer my own question it turned out I did not need to create the widget dynamically in the Drag Detected. I created a UMG widget that was just the thing I wanted to drag and drop. This widget has a exposed variable to hold the offest that will be used for the operation. Then I added that to the UMG canvas that would hold it for display as the HUD. Then I could bind a Mouse Down directly on the widget being dragged. I also added an override for the Drag Detected in that widget. The UMG HUD has the On Drop override. Your Default Drag Visual becomes self in the Drag and Drop Operation. I did use an extended Drag and Drop Operation with two variables. One is the widget reference and the other is the Vector2D offset. See the attached image bludprints.
Ultimately I should not have been creating the widget in the drag detected override and that is why it would fly in to where he mouse started the drag operation. What I wanted was to drag around a HUD element, widget, and then drop it in a new location. Very much like dragging a window around or a placing a pin on a map, etc.
Note: In the OnDragDetected I opted to not execute the remove from parent so it stays there until drop occurs. See the OnDrop override.
I have the same problem with flying from 0,0. But that solution is not helping me in my case. I want to custom new widget appear when I drag from image. As was in video tutorial by Wes Bunn, he created widget in OnDetectDrag function and then immediately plugged it as DraggedVisual into “create drag and drop operation” node. So why in this case this new widget appears at 0,0 and then fly to pivot?
Same, I need help with that issue. It seems that as soon as the dragging begins, the pointer position is set to zero, and the pivot gets messed up.
help
Ok so i found out why i was having this problem. I had this component (well two of them to be precise) called “widget interaction” in some on my blueprints which were preventing any pointer information to reach the overid drag function. I just had to uncheck the box “enable hit testing” in the interaction section. Hope it will help you too, took me many hours to figure it out.
and, one thing I ran into recently that could be part of why the widget starts from the origin or places itself at the origin. I don’t have anytime to work through how exactly to fix it, because I don’t need this working, at least in the way I initially asked the question.
The issue is in the “My Geometry” and f Get Screen Space Position and Absolute to Local. So, when determining the offset and setting position in the viewport. Using the right geometry for the calculation will greatly impact the position in the viewport. You might thing the “My Geometry” is the canvas that is for your HUD, but it is actually the UMG widget itself, so much smaller geometry. For me this ended up positioning my widget near the origin, because it was a small 100x30 widget. So, I suspect that maybe there is a way to pass the main canvas geometry so that the widget position is properly placed in the viewport. I am attaching some images that show this. Note: The On Mouse Down to get offset is the same as in a solution I answered, so I am not including an image for it. Notice how “My Geometry” is not used and a variable holding the geometry to the main canvas UMG is used. You can get the main canvas geometry in its Tick or Mouse events.
thing is, when i disable the component i talked about (the widget interaction component), this get “screen space position” coupled with “absolute to local” does his job correctly, so it makes me think that it actually get the whole frame. it shall be easy to check (by breaking the 2d infos contained in “get screen space position”, i’ll check this tonight.
That work for me! Thanks that’s been driving me crazy.
Did anyone solve this …
Anyone find a working answer for this? Mine has the same problem, the draggable widget spawns on the far left of the screen instead of on the mouse cursor.
For those still having this issue, here how i solve this:
Context: you have 2 UI:
- Main screen inventory which take all screen(1920x1080)
- Single Slot for inventory which take (100x100) using custom size screen and a size box.
The function MouseButtonDown and DragDetected, need to be inside the UI Single Slot and not in the Main screen inventory else it will take the whole screen.