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: