UMG Drag&Drop: A little help ?

Hello there fine folks of Epic :slight_smile:
I’ve downloaded the 4.5 preview from 09/09 and eagerly went about exploring. Its looking great and I’m excited for a stable build in the future.

One of the things that I’m interested in learning a little more about is the drag-drop functionality that you guys have been working on. As there’s no documentation on this fresh feature just yet, could someone tell me what the current workflow is ? I’d love to play about with it :slight_smile:

Best Regards and Much Love
MrNexy

Its on the Github, I’m calling it 4.5 preview because that’s the version the editor displays starting up. I’ve been looking through the commit log :3

Hey Nexy, where did you find the 4.5 preview or better, where did you find the patchnotes? :open_mouth:

Ah, need to have a look at Github more often. Thanks mate, see you on the forums. (:

i want to know about UMG drag&drop too.

so far i have this:

if you have a widget derived from UserWidget you can implement the ‘OnMouseDown’ where you can execute a ‘Detect Drag if Pressed’ node, which will fire off a ‘On Drag Detected’ event on that widget. Implement your ‘On Drag Detected’ and execute a ‘CreateDragDropOperation’ node. derive a class from UObject and use it to pass any info you want. plug it into the payload pin of the ‘CreateDragDropOperation’ node. Now you can just implement the ‘OnDrop’ on any of your UserWidgets and the payload pin will hold your payload object ready for you to cast back to your derived class and use.

Thank you kindly Chooka :slight_smile: I shall give that a go sometime. For the time being I have found a solution that works well enough (for now :3 )

Hi everyone – I’m still having a hard time trying to figure this out. Is there any documentation on how to achieve a simple drag & drop effect? I went through Chooka’s answer but I wasn’t able to get anything at all.

As it seems, Nexy used the canvas for this. Same to me, because we don’t know how the Drag and Drop in UMG works (if it is implemented now).

If you want to make this with the Normal HUD you need a bit work, but it’s not that hard.

I used hitboxes that i named from 0 to (letss say) 35. So i have 36 inventory places. Let’s say i have 6 rows with 6 inventory places each.

So the first row has hitboxes with the names 0 - 5. If you click on a hitbox, you get the name of the clicked hitbox. I used this “name” as the index to check my inventory. Your inventory should be set up already.

So i made 2 extra arrays. Both for the x and y value of each item icon.

When i create the hitboxes, i also save the positions inside these 2 arrays.
The first one always stays the same, the second one is used to draw the item icon and move it later.

So, you are not actualy moving the item, but more the icon and only change it’s place if you moved it to another hitbox.

Now if you click on a hitbox, you check your inventory, if there is an item in it at this place (take the hitbox name and use a Get Node for your inventory array). If yes, you update the position of this icon with your mouse position until certain events happen. I used the second array to get the positions where i want to draw my icons. So i update the Hitboxname position in this array to my mouse position. If i want to reset this position, i use the first array to get the original posititions back.

That’s the overall idea…

You would than need to think about different behaviour, like what happens if i let go of my mouse, while holding an item and there is already an item:

Do i switch these items? Or can i maybe stack the item ontop?

And so on. Took some time to get everything run, but i guess that’s how you do a drag and drop system in the canvas.

I wanted to make a Marketplace Project of this inventory, but don’t know if i may sell something like this. Still no Staff answer.

That was one hell of an answer! Thanks for your insights.

Just a heads up, Nick posted a really nice quick tutorial on drag and drop on the forums: UMG - Drag&Drop capturing mouse events. - Blueprint - Unreal Engine Forums

Thanks for the info. Next time i update my engine i will test it. At the moment i read too many questions about bugs in the new version.