I want to create a Moba/Rts like camera movement. The problem that I have is that the mouse is able to leave the Viewport.
I had some success with the following code
void UTopDownMovementComponent::LockMouse(bool State)
{
if (GEngine && GEngine->GameViewport){
FViewport* View = GEngine->GameViewport->Viewport;
if (View && View->HasFocus() && View->HasMouseCapture()){
View->LockMouseToViewport(State);
}
}
}
I call this code every frame
Movment->LockMouse(true);
. It works when I start my game in a new editor window but once I press the left or right mouse button the mouse is able to leave the Viewport.
And from that point on the mouse is always able to leave the Viewport.
Any ideas?