Mouse Cursor Position not updating

Hey programming fellows!

I already searched this topic, but did not find any solution for my problem.

For our Game I need to track the Mouse Cursor Position using

APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
PlayerController->GetMousePosition(MousePosition.X, MousePosition.Y);

At some point in the game it stops updating MousePosition.X and MousePosition.Y and the coordinates that are saved to MousePosition stay the same.
This also is hard to replicate. It does not or very very rarely happen on my computer, but on other machines this bug occurs much too often.
So I wanted to ask, if anyone here knows, what needs to happen, that GetMousePosition stops updating? I also tried to use the windows library function GetCursorPos(&p) but this also does not fix this bug.
Am I losing the focus? What causes this behavior?

Thanks in advance!

Where do you use these functions? One of them should be in tick, the other one in the construction script/ begin play. Other than that, these are the right function calls. Would try to print out a bool that shows if your PlayerController is valid and check if that’s the issue.

Thanks for the reply.
I use this within an Actor Component, tied to two different objects in our game.
Have been trying around since I posted my problem and now I am able to trigger this bug: calling our pause menu (a widget), clicking resume and BOOM → mouse position is not tracked anymore.
I dont know what happens there, since we set the game modes back to game only the mouse should work properly again =/

btw.: the function I call this whole code posted above is within a tick function. moving the player controller to begin play makes the game crash

Did you try just accessing the PlayerController and not saving it to a reference like

UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetMousePosition(MousePosition.X, MousePosition.Y);

Not exactly sure if or why the PlayerController gets a new address when calling SetInputMode or ShowMouseCursor though.

will try this now.

but the controller is valid, I just if-ed it.

no it doesn’t change anything. And since this happens after clicking the resume button I think this problem is caused within this whole pause-widget thing

Pause system in Game Mode

Graph in Pause Widget

after calling the pause widget, the mouse kind of gets locked.
it updates its coordinates on any click event (lmb & rmb) .
How to reverse this?

Yeah, Setting the Input to Game only calls SetMouseLockMode. You can set the Input to Game and UI, but some more explanation would be great why you need to track the mouse position when you are “ingame”.

I have a mechanic in it, where you need to rotate your mouse in order to screw down a screw. so I need the mouse coordinates to translate them into rotation and movement of an object