Mouse position not being updated properly

I’ve made the project in 4.9, checked 4.10 after migration as well. Clean blank project, binary versions, nothing added except the maps and widgets.

What I want, is to track the mouse position on the screen. Sounds simple. And there are functions that do that. Unfortunately, the mouse position does not update when a mouse button is clicked and held while moving, when the press happened to be on a button (regular one, from UMG).

I have tried 3 various ways to go about it, none worked. I checked all the functions that return mouse position and they all behave the same. Here is a screenshot of my first try:

As you can see, it is pretty straightforward. The widget only consists of canvas panel and a button, no logic at all. The behavior goes like this:

As you can see, when I’m moving my mouse while having left button held down, the position is not updated, even although it does print the location each next tick. I have searched through the forums and here and found some info on mouse capture events and the possibility to override mouse move. Here’s what I did in the 2nd widget (the map logic stays the same, just creating different widget):

Issue gets even worse, since the value is not updated even when I just move mouse over the button without pressing it. Same goes for the 3rd try, in which I decided to not capture the mouse and only handle MouseMove function override (deleted ButtonUp and ButtonDown, so no mouse capturing happened).

There is also Drag and Drop stuff - but I don’t need it. I just need proper mouse coordinates no matter what happens to the mouse. Even if there’s some UI involved. Any hacks or workarounds appreciated as well as a proper solution.
[link text][1]

Hello

I have a workaround for getting the position of the mouse when using drag and drop. This may be viable depending on your needs.

Example:

In this example I am finding the absolute location of the widget within the window (not the viewport), I then convert this to the viewport location. This will make it so that the original position of the widget is 0,0 effectively. So to correct what ever offset there may be I also get the original position of the widget that is being moved and subtract that from the viewport location that I have gotten. This will give me an accurate location of the widget that is being dragged within the viewport. Hopefully this is enough to get you pointed in the correct direction.

Possible suggestion for getting position:

You may be able to apply a custom cursor using a widget blueprint. This will allow you to use a similar tactic to find the widgets position that is representing the mouse and thereby finding the mouse location.

Make it a great day

Unfortunately, it does not solve my issue, since we’re not using a custom widget for cursor. Thank you for the workaround though, pretty nice actually, I’ll remember it since it might prove useful :wink:

Is this a known issue that I could somehow track or is it a bug not yet reported? I believe it’s a bug since a node that gives current mouse position should give current mouse position no matter what. We’ll probably try hacking it somehow, but I’d like to know.

Hello

After doing a bit more digging I found that this is working as intended. Buttons capture the mouse by default, that means that no input events are traveling to other widgets, including the viewport which forwards mouse information to the player, which is what PlayerController.MousePosition is reflecting. The only way to avoid this is to not use a widget that captures the mouse, which would for button mean changing the click behavior to be precise click, or on down…etc. Conditions that wouldn’t require capturing the mouse for multiple frames. I hope that this information helps.

Make it a great day

“Changing the Button Click Behavior” You saved my day!

Hi,

Is this still the correct approach? I am doing a drag and drop but I would still like to get the cursor position so I can get a hit result underneath to drop the item in the world not just another UMG widget. I was trying to take the vector 2d you show us how to make and use the deproject node I cant quite get it to work. I just need a hit result under cursor while dragging a widget. What is the best way to get that vector?

Hello GameMaster79,

The above workaround that was given should still be an easy and viable way to get your mouse position. As for help with the deprojection node. Your result may be off because of not taking DPI into account. You may want to account for the screen ratio when determining your screen position. I have provided the API documentation that describes what each pin does. I hope this helps. If you need further assistance with this node I would suggest creating a new thread for tracking purposes as it is not a bug and is not related to the current thread. I hope that this information helps.

Link: Deproject | Unreal Engine Documentation

As a note: Feel free to leave a link to your new thread in a reply (if created) so that future users can follow up.

Make it a great day

Hello thanks for getting back to me. Rather than change the DPI I went back to your example and made a few changes. It works more or less perfectly now, with one draw back. The point returned is the top left corner, which is the anchor point of the dragged widget, rather than the mouse. I started a new post and attached what I had done. It would be cool if you could take a look. I just cant seem to work out how to get that mouse offset. Thanks

Getting Mouse Position During Drag and Drop UMG