Mouselooks stops working after UI Toggle

I created a Toggle so I can access my UI using my mouse using this little bit of code

if (bShowMouseCursor)
{
	bShowMouseCursor = false;
	SetIgnoreLookInput(false);
	SetIgnoreMoveInput(false);
}
else
{
	bShowMouseCursor = true;
	SetIgnoreLookInput(true);
	SetIgnoreMoveInput(true);
}

It works ok, but I have the issue that once I click on any UI widget like a button and toggle back to the game I have to click the canvas before my mouselook works again.
If I don’t use the UI and just toggle all works fine.

I tried the Blueprint UMGInventory sample by epic, and this has the same issue for me. click first to get mouselook back.

Can someone explain to me why this happens and how to force mouse focus back to the Character input?
Thanks!

Ok I feel dumb now, I tried these last night but did not get it working, but now it work’s…maybe the hotreloading was playing me…

Well thanks a bunch!

It could be one of two things:

Input mode not set to GameOnly:

//Get player controller
UWorld* world = GetWorld();

if(world)
{
    APlayerController* pc = world->GetFirstPlayerController();
    
    if(pc)
    {
        FInputModeGameOnly inputMode;
        pc->SetInputMode(inputMode);
    }
}

Focus not set to viewport:

// Set focus to game viewport
FSlateApplication::Get().SetAllUserFocusToGameViewport();