Mouse cursor not hiding when using gamepad?

I have been building this prototype, and recently set it up to support both mouse+keyboard play as well as gamepad. I additionally have HUD glyphs set up to auto-update to the respective images whenever a new input method is detected at runtime, so you can seamlessly switch to gamepad or vice versa while the game is running.

What I need to happen is for the cursor to show when MnK is detected, or hide the cursor when gamepad input is detected. The part I have been stuck on is that the cursor won’t actually hide when I start pressing buttons on my gamepad, and I don’t know why or how to get it to hide as intended.

My architecture goes something like this:

  • I have the CommonUI plugin enabled, and inside my controller blueprint, I have it bind to a delegate called OnInputMethodChanged, which originates from CommonInput

  • When this delegate is broadcast, it returns a ECommonInputType enum which tells me whether MnK, gamepad, or another input type was the most recently detected one; so I simply check if it is MouseAndKeyboard to decide if ShowMouseCursor should be set to true or false (see picture)

I have tested this with a wired xbox gamepad connected, and even put print strings in all the right places to confirm the code is executing as it should, and I can confirm that:

  • OnInputMethodChanged is firing when, I started playing in editor on MnK but then touched something on my gamepad, or vice versa
  • The enum is returning ‘MouseAndKeyboard’ when the last input pressed was either from my mouse or from my keyboard
  • The enum is returning ‘Gamepad’ when the last input pressed was on my xbox gamepad
  • Print strings at runtime show that ShowMouseCursor is successfully being set to false as I have coded it to when the gamepad is detected, yet the cursor is not actually being hidden from the screen in these cases

Some things I have tried:

  • As shown in the picture I have tried playing around with setting the input mode to Game Only in certain places because I had seen some other reports about that somehow being the fix, but in my case it has not changed anything no matter where I call it
  • As a test I threw in a debug event on H wherein it simply toggles ShowMouseCursor back and forth, so I can just run the game and spam H on the keyboard, which seems to hide and show the cursor as it should. So it seems that cursor hiding somehow behaves differently when gamepad input is involved?

Other than that I am not sure what the proper fix is here. The Xbox gamepad I have been using is also kinda bad quality and has suffered some wear and tear but it is still functional enough to test something as simple as this; not sure if somehow the quality of the gamepad has anything to do with this though.

I do have some widgets that are in persistent use while the game is running but also don’t know how those might play into this. None of them are focusable as far as I know, and despite how much code is in some of the widgets, I never give them any authority over showing the mouse cursor or let them talk directly to my controller class (it’s usually the controller talking to them instead)

What am I doing wrong, and how can I allow use of gamepad input while still dynamically hiding/showing the cursor when needed?

Try moving the Set Input Mode Game Only to just after hiding mouse cursor, and try throwing in a Set Focus to Game Viewport just after that. I can’t repro the problem, but I’m not using Common UI since that thing is a hungry hungry hippo when it comes to stealing focus from game lol.

Or. umm, yea, isn’t hiding for me unless I move the mouse after hiding, which would kinda defeat the puropse of your input mode changed event. I fixed that with brute force by using Set Mouse Position to 0,0 right after hiding cursor and forcing focus to game viewport. Seems this tricks Slate into refreshing mouse draw.

Okay so I have tried just about every combination of how I order the following commands when gamepad input is detected:

  • Setting ShowMouseCursor to false
  • Setting input mode to Game Only
  • Calling SetFocusToGameViewport
  • Setting mouse position to 0,0
  • On a hunch, toying with SetViewportMouseCaptureMode
  • Another hunch was flushing input vs not flushing input when input mode is set to game only

Every single combination still produces the same result, wherein ShowMouseCursor is getting set to false, but the cursor is not actually hiding. This includes your suggestion of:

hide mouse cursor > set focus to game viewport > set mouse position to 0,0

and the cursor still wont be hidden.

Regarding my debug event to manually hide the cursor, I still find it very suspicious that the cursor hides as intended when the code is executed by keyboard input, but not by gamepad input, even when the same exact routine is called. I am thinking this is the real culprit here.

Let me know if that leads anywhere or if you think of any other potential solutions.

I suppose I should also mention that I am on UE 5.7.4, and in this version, the CommonUI plugin is labeled as being in beta. It did give me some weird warning when I enabled it but I have kinda been assuming it’s nothing to worry about.

I appreciate the help thus far!

Maybe the CommonInput method change event is just refiring and showing mouse again in the span of one frame. Instead of relying on event, you could try to brute force it via AnyKey event in player controller:

But, again, ComonUI is a greedy squirrel when it comes to input foci, so it might just steal it back if any activatable widgets are on screen and expecting game and ui input mode.

The keyboard test is the useful part. The same routine hides the cursor from a key, and does not hide it when a gamepad button runs it. So Show Mouse Cursor is not staying false. Something that only runs for the gamepad key is setting it back in the same frame.

That something is CommonUI. On a gamepad key the Common Input preprocessor does two things, in order. It broadcasts OnInputMethodChanged, which is your branch, cursor off. Then it reapplies the active activatable widget’s input config, and that write sets the player controller cursor from the config. A keyboard debug key does not change the input method, so the second step never runs and the cursor stays hidden. Reordering Set Input Mode, Set Focus to Game Viewport, and Set Mouse Position cannot win, because the router runs after your event. The Any Key version loses the same way while a widget is active.

Fix it on the widget. That is the writer that sticks.

On every Common Activatable Widget that stays up during play (the HUD), do not leave Input Config at Default or Menu. Default and Menu are what force the cursor back on.

Override Get Desired Input Config. When the Common Input Subsystem’s current input type is Gamepad, return Game, mouse capture Capture Permanently, and hide the cursor. When it is Mouse and Keyboard, return All or Menu, no capture, cursor shown. CommonUI calls this itself on the method change, so the controller cursor code can go.

If a gamepad pointer is still drawn after that, the analog cursor is enabled. That cursor exists to draw a pointer for a gamepad. In Project Settings, search for Analog Cursor and disable it. An enabled analog cursor will show a cursor on gamepad no matter what Show Mouse Cursor says.

Also check there is not a second activatable widget, even one with no visuals, that is the focused one and still requesting Menu. The router uses the leaf active widget, not the player controller.