# Getting Mouse Position During Drag and Drop UMG

**URL:** <https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [February 20, 2017, 5:39pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760 "2017-02-20T17:39:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameMaster79](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GameMaster79](https://forums.unrealengine.com/u/GameMaster79)\
**Post date:** [February 20, 2017, 5:39pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/1 "2017-02-20T17:39:01Z")

</div>

Hi,

I’m following up on this thread:  
[https://answers.unrealengine.com/answers/342289/post.html](https://answers.unrealengine.com/answers/342289/post.html)

Just trying to calculate the mouse position from a widget that is being dragged. Currently, I can get the position on the widget, but it is at the anchor point. The top left rather than the mouse that is dragging the widget. I’m hoping to account for that off set.

Here is the set up to get the widget position while being dragged attached.

Thanks,

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 20, 2017, 6:27pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/2 "2017-02-20T18:27:15Z")

</div>

Do you need the position of where the drag started and finished or the in-between?

---

<div class="post-metadata">

**Author:** ![GameMaster79](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GameMaster79](https://forums.unrealengine.com/u/GameMaster79)\
**Post date:** [February 20, 2017, 10:31pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/3 "2017-02-20T22:31:31Z")

</div>

Just the finish. I really only need the drop point so I can do a trace to see if an actor is there. Setting the vector 2d on tick is over kill. I’m really only using the last time its set. If that makes and sense.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 20, 2017, 11:30pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/4 "2017-02-20T23:30:33Z")

</div>

I think it makes sense; if I understood you right, you want to drag&drop a widget onto a 3d world actor. Kind of tricky.

Generally speaking you cannot track cursor position (in a traditional way) during drag operation because the data is not being sent to the controller. You can only obtain cursor position if you are dragging over another widget in which case pointer events return screenspace location - you’ll need to use that instead:

![screenp.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/4/64d8e495f2c07e74d8d28627e5c302b836cccc3e.png)

The bottom line is: as long as your drop operation ends over _a_ widget, you can get the screen location easily.

You’ll have two options here:

- the actors have a fully transparent widget attached (updating its screen location during drag&drop - so you’ll end up dropping a widget on a 3d object’s widget; you will not even need a trace here)
- a fully transparent widget covering the entire screen (or at least the gameplay area), like a border with Tint alpha set to 0 (here you’ll need to trace)

You only need to worry about it while dragging so it can be added/removed (or collapsed) to/from the viewport when dragging starts/ends.

Not sure if any other method exists.

---

<div class="post-metadata">

**Author:** ![GameMaster79](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GameMaster79](https://forums.unrealengine.com/u/GameMaster79)\
**Post date:** [February 21, 2017, 12:56am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/5 "2017-02-21T00:56:31Z")

</div>

Hey thanks,

I finally got the on drop operation to spit out the right vector 2d. I used the fully transparent widget system because I already had that set up. After Get Screen Space I used Absolute to Viewport and pulled off Pixel Position. About the offset of where in the widget you clicked to drag -the simple way to deal with that I found is the pivot enum when you create the Drag Item. I just set it to center center. So everything is going from the center of the widget. This is a good thread as there is some bad information out there about these mouse events on drag and drop.

---

<div class="post-metadata">

**Author:** ![aussieburger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aussieburger](https://forums.unrealengine.com/u/aussieburger)\
**Post date:** [August 10, 2018, 7:26am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/6 "2018-08-10T07:26:31Z")

</div>

> [@Everynone](#):
>
> You’ll have two options here:
> 
> - the actors have a fully transparent widget attached (updating its screen location during drag&drop - so you’ll end up dropping a widget on a 3d object’s widget; you will not even need a trace here)
> - a fully transparent widget covering the entire screen (or at least the gameplay area), like a border with Tint alpha set to 0 (here you’ll need to trace)
> 
> You only need to worry about it while dragging so it can be added/removed (or collapsed) to/from the viewport when dragging starts/ends.
> 
> Not sure if any other method exists.

Thanks for posting this workaround! Previously in 4.19 this was not required for drag and dropping out of a scrollbar button widget the touch positions where still passed through to the viewport. I guess Epic ‘fixed’ this behavior as it no longer worked in 4.20. Using your second workaround option I was however able to get drag and dropping from a scroll list item to the viewport working in 4.20 again 🙂

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2018, 8:40am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/7 "2018-08-10T08:40:52Z")

</div>

@\*\*[aussieburger](https://forums.unrealengine.com/member/12121-aussieburger): **A month or so ago I spoke privately with @** [michalss](https://forums.unrealengine.com/member/1083-michalss) \*\*who was looking for a way to drag and drop widgets from a panel into the 3d world that’s outside of the widget boundaries (which is pretty normal). I suggested the above method (which works fine, sure).

Now, his response was more interesting, though. We all know one can create a custom drag & drop operation; what I did not know back then was that this operation has its own overrides. I’ve yet to test it out thoroughly enough but I believe this is actually the \*correct \*way of obtaining cursor position during drag and drop rather than the hacky workaround I found.

Consider looking into the above, it’s probably a more future-proof solution since things may just change in 4.21+

---

<div class="post-metadata">

**Author:** ![aussieburger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aussieburger](https://forums.unrealengine.com/u/aussieburger)\
**Post date:** [August 10, 2018, 12:47pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/8 "2018-08-10T12:47:19Z")

</div>

> [@Everynone](#):
>
> @\*\*[aussieburger](https://forums.unrealengine.com/member/12121-aussieburger): **A month or so ago I spoke privately with @** [michalss](https://forums.unrealengine.com/member/1083-michalss) \*\*who was looking for a way to drag and drop widgets from a panel into the 3d world that’s outside of the widget boundaries (which is pretty normal). I suggested the above method (which works fine, sure).
> 
> Now, his response was more interesting, though. We all know one can create a custom drag & drop operation; what I did not know back then was that this operation has its own overrides. I’ve yet to test it out thoroughly enough but I believe this is actually the \*correct \*way of obtaining cursor position during drag and drop rather than the hacky workaround I found.
> 
> Consider looking into the above, it’s probably a more future-proof solution since things may just change in 4.21+

What do you mean exactly by it’s own overrides? Is there any documentation / threads on the custom drag and drop setup?

Thanks btw for giving an update 😉

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2018, 1:56pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/9 "2018-08-10T13:56:30Z")

</div>

Essentially, you can create your own [Drag&Drop operation](https://api.unrealengine.com/INT/BlueprintAPI/UserInterface/CreateDrag_DropOperation/index.html) - I’ve seen this covered (and used it) before, including Epic’s official guides. You can extend the class and add data to the operation. But what I mean is this:

 ![Untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/9/e953bc149ad0011071d833006ddfd0f965ad75f2.png)

This will, apparently, quite happily spit out cursor position independently of the Player Controller (which is receiving squat) even if it’s not traversing over another widget. Admittedly, I’ve yet to take it for a spin myself. If this is common knowledge then I’ve been living under the unreal rock. Never saw this documented or mentioned before and there are countless threads regarding this \*issue \*on AH.

Looking forward to driving both a widget and world object in a single Drag&Drop operation, and without additional widget helpers:

[https://drive.google.com/open?id=1ya…oBJ50qQmytjIuL](https://drive.google.com/open?id=1yaSzeu7fxt7Qhn1VqnoBJ50qQmytjIuL)

---

<div class="post-metadata">

**Author:** ![aussieburger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aussieburger](https://forums.unrealengine.com/u/aussieburger)\
**Post date:** [August 10, 2018, 7:01pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/10 "2018-08-10T19:01:28Z")

</div>

> [@Everynone](#):
>
> Essentially, you can create your own [Drag&Drop operation](https://api.unrealengine.com/INT/BlueprintAPI/UserInterface/CreateDrag_DropOperation/index.html) - I’ve seen this covered (and used it) before, including Epic’s official guides. You can extend the class and add data to the operation. But what I mean is this:
> 
> ![Untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/9/e953bc149ad0011071d833006ddfd0f965ad75f2.png)
> 
> This will, apparently, quite happily spit out cursor position independently of the Player Controller (which is receiving squat) even if it’s not traversing over another widget. Admittedly, I’ve yet to take it for a spin myself. If this is common knowledge then I’ve been living under the unreal rock. Never saw this documented or mentioned before and there are countless threads regarding this \*issue \*on AH.
> 
> Looking forward to driving both a widget and world object in a single Drag&Drop operation, and without additional widget helpers:
> 
> [https://drive.google.com/open?id=1ya…oBJ50qQmytjIuL](https://drive.google.com/open?id=1yaSzeu7fxt7Qhn1VqnoBJ50qQmytjIuL)

Many thanks for that! Works as expected and much cleaner than using the previous workaround. No idea why it needs to be so complicated & abstract to setup though. Not sure why you can’t retrieve this information from the default Drag and Drop blueprint object. Like some sort of Dragging event binding?

Anyway great that it is working now in a relatively future proof way 🙂

---

<div class="post-metadata">

**Author:** ![jdannenbring](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jdannenbring](https://forums.unrealengine.com/u/jdannenbring)\
**Post date:** [May 24, 2019, 6:10am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/11 "2019-05-24T06:10:40Z")

</div>

Super helpful, thanks! Didn’t think to do this when the drag ate all my mouse position info. Works like a charm. If, like me, the next person is simply looking for what 3D objects are under their mouse cursor while dragging:  
1 - Override the Dragged event in your custom Drag&DropOp class (shown in Everynone’s example above)  
2 - Pass the PointerEvent that the event Dragged contains off to your player controller or whichever class is handy.  
3 - Process the PointerEvent with GetScreenSpacePosition (that gives you X/Y)  
4 - Deproject Screen to World (that gives you World position/direction  
5 - Use a LineTrace to see whats down there!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 24, 2019, 6:30am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/12 "2019-05-24T06:30:13Z")

</div>

Yup, I’ve been using it ever since.

---

<div class="post-metadata">

**Author:** ![jimmay.10](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jimmay.10](https://forums.unrealengine.com/u/jimmay.10)\
**Post date:** [May 29, 2019, 1:41am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/13 "2019-05-29T01:41:57Z")

</div>

> [@jdannenbring](#):
>
> Super helpful, thanks! Didn’t think to do this when the drag ate all my mouse position info. Works like a charm. If, like me, the next person is simply looking for what 3D objects are under their mouse cursor while dragging:  
> 1 - Override the Dragged event in your custom Drag&DropOp class (shown in Everynone’s example above)  
> 2 - Pass the PointerEvent that the event Dragged contains off to your player controller or whichever class is handy.  
> 3 - Process the PointerEvent with GetScreenSpacePosition (that gives you X/Y)  
> 4 - Deproject Screen to World (that gives you World position/direction  
> 5 - Use a LineTrace to see whats down there!

3a. Use the AbsoluteToViewport node to convert the desktop coordinates to pixel position in the screen before the deproject. Otherwise it works fine in fullscreen, but not so much in windows.

---

<div class="post-metadata">

**Author:** ![Nonlin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonlin](https://forums.unrealengine.com/u/Nonlin)\
**Post date:** [April 29, 2021, 4:36am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/14 "2021-04-29T04:36:36Z")

</div>

Why is this still so cryptic? The link to the example is dead and there is no override for the dragged event in a UMG class?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [April 29, 2021, 7:44am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/15 "2021-04-29T07:44:13Z")

</div>

> [@Nonlin](#):
>
> Why is this still so cryptic?

`Because it's undocumented, arcane knowledge obtainable only by those knowing a secret handshake.`

* * *

The below assumes you have overridden and using a Game Mode, a Player Controller and created a custom Drag & Drop Operation.

* * *

- in the Player Controller

A Custom Event converts screen space to world space via deprojection and sets actor’s position:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/7/17f6484605190263ef07310e7125014b95719968.jpeg)

* * *

- in the Custom Drag & Drop Operation blueprint

Event Dragged spits out screen space coordinates and feeds them to an Event Dispatcher, we also provide an actor reference (more on that below). We’re using an actor, not an object - the assumption is that you actually want an actor. This _Actor Payload_ variable is flagged as _Instance Editable_ and _Exposed on Spawn_.

You could use the standard Drag OP Payload Object but you’ll need to cast to actor later on. An actor is more convenient in this instance.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/5/9511644c3b0d67b80111eece4fd0818664582ea6.png)

* * *

- in the Widget being dragged:  
– when drag is detected, we spawn an actor  
– create the abovementioned custom Drag Op and feed the actor’s reference into Actor Payload (explained above)  
– up to you how to handle the Default Drag Visual part  
– we then bind the Drag OP’s Dispatcher call with the Player Controller’s Event (first pic)  
– return drag result

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/3/b3cc4a510ee3c9f09a8329b521dbcbc67a5bd84e.jpeg)

Should work in any resolution / DPI / aspect ratio. _fingers crossed_

* * *

There are other methods of handling similar behaviours. The approach would depend on what the end goal is and how it’s supposed to work. If in doubt, do provide the details.

---

<div class="post-metadata">

**Author:** ![Macarmoni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Macarmoni](https://forums.unrealengine.com/u/Macarmoni)\
**Post date:** [August 1, 2021, 7:59pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/16 "2021-08-01T19:59:30Z")

</div>

Thank you so much

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [September 7, 2022, 10:51am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/17 "2022-09-07T10:51:30Z")

</div>

Hi, sorry for bringing up (again) an old topic, I managed to follow the instructions but I have two issues:

- I think the video speaks for itself  

- Once I do an action (like jumping or toggling between first and thrid person) I can’t drag the widget anymore

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 7, 2022, 11:10am UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/18 "2022-09-07T11:10:59Z")

</div>

> [@someonelsee1](#):
>
> I think the video speaks for itself

Disable collision on the object you’re dragging and enable it only once dragging is finalised. Otherwise, the line trace will hit the object (here, a chair) that you are dragging. We want to trace against the floor only, for example. Unless you wish to stack a chair on top of another chair, ofc.

Alternatively, look into how custom collision channels work - here the trace can be set up in such a way that certain groups of objects can be easily ignored. This is by far the most efficient method and gives you a lot of control over how tracing behaves.

Perhaps you want to place lamp sconces in areas that make sense only - walls, rather than floors. Collision channels would allow you to ignore certain surfaces:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/3/6f3422c25b23e895da56cfa54a8fe65cf18e0bb6.png)

Placing a wallpaper on a wall blocked by a wardrobe would be possible because dragging wallpapers uses a channel that furniture ignores.

* * *

> Once I do an action (like jumping or toggling between first and thrid person) I can’t drag the widget anymore

Sounds like the widget has lost focus. Are we in `Game and UI Input Mode`? Make sure the root of the widget has the `isFocusable` flag enabled.

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [September 7, 2022, 12:24pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/19 "2022-09-07T12:24:26Z")

</div>

> [@Everynone](#):
>
> Disable collision on the object you’re dragging and enable it only once dragging is finalised.

Thanks, and how do you do this?  
I’ll look up on trace channels.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 7, 2022, 12:34pm UTC](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760/20 "2022-09-07T12:34:59Z")

</div>

`Static Mesh Components` have granular collision settings (and presets) which can also be adjusted dynamically. Perhaps the chair should start with no collision:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/b/82b819c2191f2a590e7896a744bd17d4be6032e6.png)

And once it’s plopped down, it can be re-enabled.

[Next page](https://forums.unrealengine.com/t/getting-mouse-position-during-drag-and-drop-umg/85760.md?page=2)
