Prevent mouse from losing control over game

Hello

I’m making some UIs. When I open the UI and click on the button or anywhere else, the viewport or editor isn’t focused anymore and doesn’t receive mouse input. When I then close the UI, the game takes keyboard input but not mouse input. The player character doesn’t turn with the mouse.

SetInputModeGame&UI only prevents the mouse from leaving the window but it still doesn’t receive input.

Is there a solution to this?

How do I prevent the mouse from tabbing out?

Thanks