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

Hello @Knampf1 ,
It might be that the issue is that the Input Mode is not being properly restored when closing the UI. When the widget takes focus and Game & UI is used, if it is not explicitly set back to Game Only afterward, the viewport does not recapture the mouse even if the widget is hidden.

You could try the following setup: when opening the menu, set Visibility to Visible, set Show Mouse Cursor to true, and then call Set Input Mode Game and UI, assigning your menu to Widget to Focus and setting Mouse Lock Mode to Lock Always. When closing the menu, set Visibility to Collapsed, set Show Mouse Cursor to false, and finally call Set Input Mode Game Only.

Calling Set Input Mode Game Only when closing the UI is what restores mouse capture and allows the player to rotate the camera again.
You could try the following setup:

Hope it helps!

1 Like

That fixed it, thanks.

1 Like