How to correctly set mouse position from PlayerController?

void AARPlayerController::BeginPlay()
{
Super::BeginPlay();

	ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(Player);
	if (LocalPlayer)
	{
		FViewport* Viewport = LocalPlayer->ViewportClient->Viewport;
		
		FIntPoint ViewportSize = Viewport->GetSizeXY();
		//FVector2D ViewportSize = GEngine->GameViewport->Viewport->GetSizeXY();
		FVector2D MousePosition;
		//just testing probabaly need less hardcoded math, for the subtraction part.
		MousePosition.X = (ViewportSize.X * 0.5);
		MousePosition.Y = (ViewportSize.Y * 0.5);
		Viewport->SetMouse(int3MousePosition.X), int32(MousePosition.Y));
		GEngine->AddOnScreenDebugMessage(1, 10, FColor::Red, FString::FormatAsNumber(MousePosition.X));
		//GEngine->AddOnScreenDebugMessage(0, 2, FColor::Blue, FString::FormatAsNumber(MousePosition.Y));
	}
	/*
		For whatever reason, telling it to replicate in constructor is not enough.
		We must do so also in BeginPlay().

		Maybe somwhere else in hierarchy call would also work, like PostInitializeComponents.
	*/
	Inventory->SetIsReplicated(true);
	Abilities->SetIsReplicated(true);
	
}

I expected this code to spawn cursor exactly (or almost exactly) at center of the screen.
But:

https://dl.dropboxusercontent.com/u/70400220/Unreal-questions/cursor-issue.jpg

This happen. Any ideas what is wrong ?

edit:

What I discovered so far (resolution 1280x720)

Hardcoding proper coordinates (640, 325), does change anything.

Hardcoding coordinates like (1270,325) pushed cursor to right side of the viewport.

That makes me think, that when cursor is set, the screensize is not know yet. But on the other hand AddOnScreenDebugMessage print expected value.

Try to unlock the cursor first with FSlateApplication::Get().LockCursor(NULL)

I hacked My solution around. It’s not pretty but it works.

void AARHUD::DrawHUD()
{
	Super::DrawHUD();

	// find center of the screen/Canvas
	//const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
	//if (CrosshairTex && Canvas)
	//{
	//	FVector2D CrosshairDrawStart(Center);
	//	CrosshairDrawStart.X -= CrosshairTex->GetSurfaceWidth() * 0.5f;
	//	CrosshairDrawStart.Y -= CrosshairTex->GetSurfaceHeight() * 0.5f;

	//	FCanvasTileItem TileItem(CrosshairDrawStart, CrosshairTex->Resource, FLinearColor::Red);
	//	TileItem.BlendMode = SE_BLEND_Translucent;
	//	Canvas->DrawItem(TileItem);
	//}

	if (CursorDirty)
	{
		//FSlateApplication::Get().LockCursor(NULL);
		ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(GetOwningPlayerController()->Player);

		if (LocalPlayer)
		{
			FViewport* Viewport = LocalPlayer->ViewportClient->Viewport;

			//FVector2D ViewportSize = GEngine->GameViewport->Viewport->GetSizeXY();
			FVector2D MousePosition;
			//just testing probabaly need less hardcoded math, for the subtraction part.
			MousePosition.X = Canvas->ClipX * 0.5f - 40.0f;
			MousePosition.Y = Canvas->ClipY * 0.5f + 56.0f;

			Viewport->SetMouse(MousePosition.X, MousePosition.Y);
			GEngine->AddOnScreenDebugMessage(1, 10, FColor::Red, FString::FormatAsNumber(MousePosition.X));
			DirtyFrameCount++;
			if (DirtyFrameCount > 5)
			{
				CursorDirty = false;
				DirtyFrameCount = 0;
			}
			//GEngine->AddOnScreenDebugMessage(0, 2, FColor::Blue, FString::FormatAsNumber(MousePosition.Y));
		}
	}

Viewport->SetMouse() sets the cursor position in screen coordinates. And with screen, I mean the actual physical screen, not just the game viewport.