SetMousePosition doesn't work at BeginPlay()

Hi guys, a problem I encounterd is very werid.
In the very begining of the game, I wish that the mouse cursor would appear which be located in center of screen.
But actually its location is not what I wished…

Here my codes… very simple codes… but it seems to does not work accurately…

void ADMCPlayerController::BeginPlay()
{
	Super::BeginPlay();
	
	FIntPoint viewSize = GEngine->GameViewport->Viewport->GetSizeXY();
	SetMouseLocation(viewSize.X / 2, viewSize.Y / 2);

	UE_LOG(LogTemp, Warning, TEXT("%s"), *viewSize.ToString());
}

The follow image illustrate where the cursor is after the codes executed:

PS: As you may have suspected, the output of the UE_LOG is very correct…

Same problem here.

Hello,

it looks like the window position information is not yet updated in BeginPlay(). Therefore, the cursor position is set relative to the window position (0, 0).

I resolved this by creating a timer that after Wait calls the OnTimer_Cursor().

DMCPlayerController.h

void OnTimer_Cursor();

FTimerHandle CursorTimerHandle;

DMCPlayerController.cpp

#include "TimerManager.h"

ADMCPlayerController::ADMCPlayerController()
	:Super::APlayerController()
{
	bShowMouseCursor = true;
}

void ADMCPlayerController::BeginPlay()
{
	Super::BeginPlay();
	
	//OnTimer_Cursor();
	float Wait = 0.01f;

	GetWorld()->GetTimerManager().SetTimer(CursorTimerHandle, this, &ADMCPlayerController::OnTimer_Cursor, Wait, false);
}

void ADMCPlayerController::OnTimer_Cursor()
{
	FIntPoint viewSize = GEngine->GameViewport->Viewport->GetSizeXY();

	SetMouseLocation(viewSize.X / 2, viewSize.Y / 2);
}

It also worked when I set Wait for 0.00000001.