# Detect Drag and onClicked conflict

**URL:** <https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579>\
**Category:** UI\
**Tags:** drag-and-drop, click-event, inventory-system, unreal-engine, mouse-click, question, UMG\
**Created:** [December 30, 2020, 4:38pm UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579 "2020-12-30T16:38:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1dedd871](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1dedd871](https://forums.unrealengine.com/u/anonymous_user_1dedd871)\
**Post date:** [December 30, 2020, 4:38pm UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579/1 "2020-12-30T16:38:48Z")

</div>

Hello!  
I’m trying to implement Drag and Drop system in my Inventory, but i’ve encountered a problem - when i override OnPreviewMouseButton event and put “Detect Drag if pressed” node in there, event onClicked stops working - it works only with second click, if i press the button twice, like if Detect Drag consumes the first click.

I’ve tried to use “Precise click” in button settings, but it doesn’t help.

Here’s my widget with button:

![325947-clip2net-201230212820.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/5/345249875eda2585d7af1eca20d3207bb1f436a6.png)

How can i make Detect Drag and onClicked work together?

---

<div class="post-metadata">

**Author:** ![Koaku](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Koaku](https://forums.unrealengine.com/u/Koaku)\
**Post date:** [January 2, 2021, 2:55am UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579/2 "2021-01-02T02:55:17Z")

</div>

I think this could be to do with the OnPreviewMouseButton overriding the On Clicked

![326078-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/6/2/362013ea6ced1e658617f7754de496e520f7f1eb.png)

I’m not sure you can directly fix this it might just be how the thing works, and i’m sure the standard OnMouseButtonDown doesn’t work with the drag system as it cant detect left click.

You could try handling your on clicked logic inside the OnPreviewMouseButton

Or

use a event dispatcher, call a function or call an event if you don’t want to handle your logic inside the OnPreviewMouseButton

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [January 5, 2021, 2:59pm UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579/3 "2021-01-05T14:59:25Z")

</div>

Hello! Take a look at this [OnMouseDown and button in UMG - Blueprint Visual Scripting - Unreal Engine Forums](https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/118039-onmousedown-and-button-in-umg). It seems that even if you are using Precise Click you can have problems with button Visual States. Can it be suitable solution to just have some decorator around Button for drag and drop purpose?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1dedd871](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1dedd871](https://forums.unrealengine.com/u/anonymous_user_1dedd871)\
**Post date:** [January 6, 2021, 4:02pm UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579/4 "2021-01-06T16:02:50Z")

</div>

Yes, adding a border indeed solved a problem, thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1dedd871](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1dedd871](https://forums.unrealengine.com/u/anonymous_user_1dedd871)\
**Post date:** [January 6, 2021, 4:04pm UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579/5 "2021-01-06T16:04:36Z")

</div>

Thanks, i moved all the logic from onClicked to OnPreviewMouseButton, and now double click is handled correctly!

---

<div class="post-metadata">

**Author:** ![BigMartin58](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BigMartin58](https://forums.unrealengine.com/u/BigMartin58)\
**Post date:** [June 25, 2024, 6:53am UTC](https://forums.unrealengine.com/t/detect-drag-and-onclicked-conflict/476579/6 "2024-06-25T06:53:43Z")

</div>

I know I’m a few years behind here, but for any future folks, this is the system I made and it is working flawlessly, but it involves a few steps.

I basically made a custom drag detector.

First, in the widget with the button, I override ‘Preview Mouse Button Down’ but return it unhandled so it doesn’t consume the input.

 ![Screenshot 2024-06-24 230131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/f/b4fd907e83c06ce4b8fc72ab12937c035512a844.png)

Then I send that input to a custom event and create a variable.  
 ![Screenshot 2024-06-24 230204](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/3/7c3e5f89de12a46945636725e272a89b2865fe77.png)

After that, I assign the ‘On Released’ dispatcher for the button to another custom event and call a custom event dispatcher with a reference to the widget with the button.

 ![Screenshot 2024-06-24 230223](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/b/3/8b3305bd68bc5a57ee12e0a83c3b014ba073544e.png)

Continuing, when I populate the parent widget with the widget that contains the button, I assign my custom event dispatcher to yet another custom event (except in the parent widget).

 ![Screenshot 2024-06-24 230348](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/5/4/45478c231d6428cab84dfff6ca8b4c02006e8207.png)

On that custom event, I then check if a drag was detected (below). If a drag is not detected, then the code for the button clicked fires.

 ![Screenshot 2024-06-24 230410](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/4/a2425ba7d9cd75e94dce39faef30b77173d0e13c.png)

In the parent widget, I override ‘On Mouse Button Up’, again unhandled. I untick the first boolean and execute the previous custom event. Same as if I released the button.

 ![Screenshot 2024-06-24 232649](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/e/a/5eaa7b44a7321a2893071411207d213adbc60e01.png)

Finally, on a tick event (I’m sending to another custom event), I first check if a drag was detected. The first execution of this should always be false since I’m setting it to true only if it is false. On false, I make sure the mouse button is down with the boolean I made earlier and then I check to see if the mouse moved vertically (this can be either or both) and if that’s true, a drag was detected. Now, the next tick, the first branch will be true. Now I can use the same delta input to offset the scroll box (or you can get the mouse position and ‘hold’ whatever your dragging). I have no need for the ‘OnDrop’ function/override, however you could use the false output of the mouse release event to ‘Release’ the dragged object (you would need to use a button and execute ‘OnHovered’ and send the widget reference to the parent to get _where_ you want to drop it).

 ![Screenshot 2024-06-24 230623](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/5/6/556f57a131577968f3d14bc5dda2b8de27da63d9.png)

Here is a demonstration of the code (I don’t have app functionality yet but it would work, as I tested with a print string):  
 ![ezgif-7-97fd659785](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/d/97d24c41b8fbb2c9518d28cc7c9e91ce190138a2.gif)
