Hi,guys:
I want to get mouse position when pressing a button, there are three functions that I can use, GetMousePositionOnViewport, GetMousePositionOnPlatform, or GetMousePositionDPIScaled, none of them work.
Please help me if you have any solution, thank you so much!
Thank you for your help, in fact, I have tried this for many times, when mouse is pressing, input mode will be switched to UI mode, so this function can not access mouse position any more, (0,0,0) will be returned.
Yes, they do return values, but I want to get values form 0 to viewport size, none of them returns expected value.
GetController()->GetMousePosition() returns currect value but it won’t change its value when performs a hold mouse movement.
GetMousePositionDPIScaled behaves the same.
GetMousePositionOnPlatform returns system mouse position which is not expected in my case.
GetMousePositionOnViewport returns value bigger than viewport size.
Maybe I haven’t had my question clear, so I comment here again:
those functions do return values, but I want to get values form (0,0) to viewport size, none of them returns expected value.
GetController()->GetMousePosition() returns currect value but it won’t change its value when performs a hold mouse movement.
GetMousePositionDPIScaled behaves the same.
GetMousePositionOnPlatform returns system mouse position which is not expected in my case.
GetMousePositionOnViewport returns value bigger than viewport size.
And returns the correct viewport coordinates. Perhaps show us how you do it so we can poke holes in your method - it might help, since I sense some confusion here.
performs a hold mouse movement
What do you mean by that, for example? I assumed you meant hold mouse button down but I might be wrong here.
GetMousePositionDPIScaled behaves the same.
It does not behave the same. It uses scaled DPI whose curve you can set up in the Project Settings:
Thank you for your help, in fact, I
have tried this for many times, when
mouse is pressing, input mode will be
switched to UI mode, so this function
can not access mouse position any
more, (0,0,0) will be returned.
That’s normal. In UI mode, the Player Controller does not receive mouse input - that’s the whole point of using this mode. Perhaps you can tell us what you’re trying to do.
From what I gathered you want to obtain window mouse coordinates while in UI mode. You cannot use the PC for that; in UI Only mode, it’s the widget that handles cursor data at this point - take it from the widget. For example, overriding onMouseMove returns coordinates.
It is a similar situation to a typical Drag & Drop behaviour - the Player Controller has no clue where the cursor is when you drag items in the inventory.
What you’ve mentioned so far leads me to believe that by saying pressing button, you did not mean an input key at all but a widget button instead, in which case you can get your Pixel Position at any time like so:
I am very grateful for your detailed answer, as you said, I want to get mouse position when mouse is pressing down and moving around, it is because of you that this world has become better.
Hi, I’m trying to reproduce this. It works perfectly with mouse click.
I would like to get a similar result with touch on Android instead of mouse. I get the coordinate 0.0.
Thanks for the quick response.
Your solution is of course correct. My problem is that it works in the empty part of the widget, while I’m trying to make it work while clicking a button. The button however seems to completely absorb the input.
Essentially I’m trying to implement, without success so far, a swipe mode on the button, recording the start and end positions.
Yeah, that’s the problem with the native button - or at least a problem with trying to make it do something it was never intended to do - they’re stubborn like this, and they consume input hungrily. Nice to have if you want a click / tap. But that’s it.
Make your own user widget button out of a border / image - this way you get to control everything. Also makes maintenance easier later on.