GetMousePosition Always Returns the Same Coordinates

When using the following code, I always get the same output:

float x, y;
APlayerController* pC = UGameplayStatics::GetPlayerController(GetWorld(), 0);
pC->GetMousePosition(x, y);
mouseDragStart.X = x;
mouseDragStart.Y = y;

I’ve also tried the blueprint equivalent and get the exact same result. Every time I start up a new editor window to run a test, it chooses a seemingly random point that it will then stick to for the remainder of the test session and never deviate from.

Has anybody else run into this?

Hello ,

Are you showing your mouse cursor to ensure that the mouse cursor is actually moving? The only thing I could think of that would cause this would be to be hiding the mouse cursor and controlling the camera with it, but I’m not even sure that would cause it. I’ll do some experimenting to see if I can get the same result.

I tried to get the same result but I’m not having any issues with the value. Specifically, I tried opening up a new project based off the TopDown template and setting it to print out the mouse’s X and Y to the output log whenever I click. It is giving accurate values without an issue.

Hi ,

I managed to figure this out, but it took a lot of trial and error. I was using an invisible button to detect mouse/touch press, click and release events and what I noticed was that events tied to that button always produced the results described above ^. Once I replaced the button with an invisible image and overrode the appropriate touch/move functions for the entire widget, the issue seemed to resolve itself.

Additionally, my project is using touch events and is responding to “OnTouchEnded” and “OnTouchStarted”, but won’t respond to “OnTouchMoved”. “OnMouseMoved” does work, however.

I assume the button issue is tied to them “Handling” events. This isn’t the firs time I’ve had buttons soak up events without bubbling or produce erratic results when calling events. The image produced some similar issues until I marked the events as “unhandled”.