[C++] GetMousePosition giving weird values

Hi there!

I’m trying to implement a RTS style camera. For that I’m basically using some kind of SpectatorPawn. I want to be able (like in most RTS) to move the camera by putting my mouse against the border of the viewport. I got it kind of working but sometimes, GetMousePosition gives me (0,0) even though I’m not at all in the top left corner. This is mostly happening when I’m against the left border of the screen.

Here is the code I use to move my pawn when my mouse is at maximum 2pixels from the border of the screen :

	int32 Width, Height;
	float MouseX, MouseY;
	GetViewportSize(Width, Height);
	GetMousePosition(MouseX, MouseY);
	ACameraPawn* Pawn = Cast<ACameraPawn>(GetPawn());

	if (MouseX <= 2. && MouseX >= 0.) { Pawn->MoveRight(-10); }
	else if (MouseX >= Width-2 && MouseX <= Width) { Pawn->MoveRight(10); }
	if (MouseY <= 2. && MouseY >= 0.) { Pawn->MoveForward(10); }
	else if (MouseY >= Height-2. && MouseY <= Height) { Pawn->MoveForward(-10); }

If you need any other detail, just ask. I can’t get my head around this issue. I even tried to use
SetLockMouseToViewportBehavior to lock the cursor in the viewport in case it was just getting out for some reason, didn’t work.
Thanks in advance =)

Edit : I just implemented the exact same code in blueprint, it’s working perfectly

I don’t understand and would really like to get it working with C++ :confused: