4.7 Lock mouse to viewport problem

EDIT: This doesn’t really fix it. Setting “Use Mouse for Touch” changes click behaviour alltogether.


I just found out what resolves this issue for me (I don’t know why though).


  • Go to Project Settings > Engine - Input.
  • Under Mouse Properties, check Use Mouse for Touch.

Lock Mouse to Viewport: Project Settings - Use Mouse for Touch


This toggles setting “bUseMouseForTouch=True” in DefaultInput.ini - now setting “Default Viewport Mouse Lock” works as intended, as well as using “Set Input Mode…” nodes.

Cheers!

1 Like

awesome man this worked for us thanks

ok maybe not now you cant use mouse for any inputs weapon wont fire :frowning: looks like were back to square one

Right, seems this changes more than I thought of :frowning:

Hi , do you have any news on that issue?

Somehow on “Mouse Release” input mode is being changed (when no mouse cursor is shown), and so game doesn’t lock mouse anymore. I’d love to know what dev’s are writing on that issue, if there’s a consent that it’s a bug or if some think that it is working as intented and we should do things differently to get behaviour we want.

Any more info on this would be great, thank you!

Ok, I found a work around for my situation that may be useful for some others.

I took Lock Mouse to Viewport input from Set Input Mode Game and UI and promoted it to a variable make sure it’s default state is set to true.

Then I set variable to true when mouse button is released.

From set variable node I connected it back into Event Begin Play sequence.

I may be breaking things, but for now it seems to work.

98287-promote.jpg

in issue list UE-7293 says it’s fixed and target 4.13
but in 4.13preview, it still seems broken!

I just tested this in 4.13.0 Preview 1 and I am showing that it is working. Are you pressing any buttons that would take focus away? Did any pop ups take focus away from editor?

101729-qq图片20160806115446.png

with this setting, viewport still lose locking after first click

supply: i test a clean new project, it’s ok, locking is always valid, but if make a call to “SetInputModeGameOnly”, then it goes wrong as before.

hi , i read source and find problem:

void FInputModeGameOnly::ApplyInputMode(FReply& SlateOperations, class UGameViewportClient& GameViewportClient) const
    {
    	TSharedPtr<SViewport> ViewportWidget = GameViewportClient.GetGameViewportWidget();
    	if (ViewportWidget.IsValid())
    	{
    		TSharedRef<SViewport> ViewportWidgetRef = ViewportWidget.ToSharedRef();
    		SlateOperations.UseHighPrecisionMouseMovement(ViewportWidgetRef);
    		SlateOperations.SetUserFocus(ViewportWidgetRef);
    		SlateOperations.LockMouseToWidget(ViewportWidgetRef);
    		GameViewportClient.SetMouseLockMode(EMouseLockMode::LockOnCapture);

see last line: it use an arbitrary param LockOnCapture, which should be current (last setting) value

We’re looking into this and will respond as soon as we have additional information. Thank you!

Any updates on this bug? It’s my understanding that this has been marked as a major issue for almost 2 years now, since version 4.6, and still has not been resolved. All that aside, I’d just like to have a fix or at least a workaround.

UE-7293 was fixed back in 4.13.

Im also stuck here…

  • ‘use Mouse for Touch’ enabled,
    moves camera, but don’t shoot
  • 'use Mouse for Touch disabled,
    shoots but not captures mouse

(is capturing mouse movement only when a mouse button is pressed)

Version 4.16.1

Just wanted to say thanks for this;

In C++ on Release of Mouse Button add

SetInputMode(FInputModeGameOnly());

This Keeps cursor in Viewport, when i added FInputModeGameAndUI it still allowed me to click out of viewport after initial click

In engine version 4.25.1 still having same problem. my solution is…

  1. set ‘show mouse cursor’ on
  2. make personal cursor widget
  3. trace mouse location on screen and make cursor follow that.

There’s got to be a little performance cost.

This was one of many pages I found looking for help when I ran into this same problem. I finally figured out a solution that worked for me. 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 -

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