How can I have my mouse give me information from wigets it is near?

So I have an inventory system, and I have items that can be moved. To move the items, I need the following…

2 variables from the button that the mouse was pressed on.
The button that the mouse was pressed ons parent name.

2 variables from the button that the mouse was released on.
The button that the mouse was released ons parent name.

These variables will then be set in the controller, and an event will be called to move the items.

What is the best way to do this?

when you create the widgets, you can give them a reference to your custom type of player controller.

in each button widget, you can override OnDragDetected and OnDrop.

OnDragDetected, you can call a function in the player controller which accepts a UserWidget as an input, and pass the widget to the controller to store in a variable.

OnDrop, you can call another function in the player controller that finishes the drag drop, passing itself to the controller.

you will probably also want to make a subclass of DragDropOperation, which you can create after OnDragDetected, so you can have a widget that gets dragged with the mouse cursor.

here is a good drag and drop tutorial:

Thanks, Ill try this out. Also I started watching this tutorial, but didn’t watch much of it because I didn’t really feel like building a whole new inventory system, since I already have one that functions perfectly, other than being able to drag items :slight_smile:

So I couldn’t get this to work… then I realized that I probably needed to make a drag and drop operation when the mouse button is down. So inside the button widget I want to move, I overrode the on mouse button down, and tried to create a drag and drop operation. It still wouldn’t work, so I put a print string node in there to see if it was even being called. Nothing happened. So what am I doing wrong?

OnMouseButtonDown will give you a MouseEvent reference, where you can call DetectIfDragIsPressed, which should trigger the OnDragDetected event.