Lock Mouse To Viewport

I am using the Set Input Mode Game and UI blueprint to display my UI and give it input and I would also like to use it to lock my mouse inside the viewport. The node has an option to lock the mouse to the viewport, but it does not seem to work… Is this something that is not implemented yet, and if so are there any work arounds?

In case you or someone else is (still) having trouble with this, here is the solution:

  1. Put the “Set Input Mode Game and UI” directly in your widget. For some reason it will work there.

  2. The mouse can still escape the viewport by wildly clicking and moving the cursor against the viewport borders. If you set the “Input Mode Game and UI” every Tick it is highly unprobable (yet not impossible) that the cursor can escape the viewport this way.

Hello, I actually was having issues when using “Set Input Mode Game and UI” on my BP_Player_controler, my mouse would go outside the viewport after getting items on the ground and would not lock back. So I moved it to My BP_PlayerCharacter and changed to Set Input Mode Game Only and worked better for me. Here is the example:

@Exdraz I had similar problems and what I found was I actually has to have the a flip flop that did the “Set Input Mode Game and UI” when I needed it and “Set input Mode Game Only” when I needed. So instead of just going with one mine has both in there.

I made a video and wrote an article sharing my experience and solution to this problem.

Toggling cursor visibility, mouse capture mode and locking to a viewport inside of Unreal Engine 5 - YouTube

Toggling cursor visibility, mouse capture mode and locking to a viewport inside of Unreal Engine 5 via Blueprints – Brock Harrison Austin Barnett (brockbarnett.me)