How to stop virtual gamepad cursor rapidly swapping between input modes with Common UI?

After using the solution here: [Common UI] How to show mouse cursor with gamepad and desactive the cursor recentering ? - #6 by zero.soul
The problem doesn’t go away for me using those console commands because it thinks that the game is switching rapidly between gamepad and mouse (due to the virtual cursor sending mouse input events). It will continuously reset the cursor position.

Turning on an input lock when the virtual cursor is turned on fixes it so you can use the virtual cursor. However you then have strange issues with alt-tabbing the game and can’t visually swap between keyboard and mouse input actions in menus.

Anyone have an idea of what could be done to stop this issue?
Is there a way to tell the difference between simulated mouse movement and actual mouse movement when deciding to change input types?

I found somewhat of a fix, though it’s not perfect and I had to edit UCommonInputSubsystem. I added a function called IgnoreNextMove and put this inside the function

if (CommonInputPreprocessor)
{
	CommonInputPreprocessor->bIgnoreNextMove = true;
}

Next, When the analog cursor calls UpdateCursorPosition I call the new function. You’ll need to find the local player to do this. My game analog cursor stores the player controller when it is enabled and we get the local player from there.

UCommonInputSubsystem* CommonInputSubsystem = LocalPlayer->GetSubsystem<UCommonInputSubsystem>();
if (CommonInputSubsystem)
{
				// Common Input should ignore next move since it will be a simulated mouse move
				CommonInputSubsystem->IgnoreNextMove();
}

And that’s it. I no longer need to lock input while the virtual cursor is on. There are still some weird things that happen from time to time and the cursor resets if I click a button, but so far it’s working a lot better. (I may try adding an ignore next click bool like the ignore next move in the input pre processor)

One problem though is starting the game and opening the menu, you have to move the cursor using the mouse once after the menu is opened before the virtual cursor behaves using the joystick… So that’s not fully a fix unfortunately…

It’s not jumping to the center though, but appears to be clamped to whatever location it was when you first open the menu. I wonder if it caches geometry too soon and the screen size is 0 and therefore clamped.

It also sometimes happens when alt-tabbing then returning to the game, by clicking on the game before moving the game pad while a menu is open and the analog cursor is enabled.

It happens sometimes with windows+tab and then clicking the game window that pops up.

Okay so I discovered there is an FCommonAnalogCursor that is fighting our analog cursor for control of the cursor in some widgets and sometimes when alt-tabbing. Its tick function often sets the cursor to the center of the screen.

Commenting it out in UCommonUIActionRouterBase::Initialize line 242-243 like so:

//AnalogCursor = MakeAnalogCursor();
//PostAnalogCursorCreate();

Stops the issue for the most part. However now there is another issue where something else is wrestling for control on first time opening menu with gamepad only… But it doesn’t happen nearly as often, and generally only happens when the cursor starts off screen.

Clicking anywhere (or sometimes just moving the mouse) fixes it. And it’s no longer happening on alt-tab as far as I can tell.

maybe you should override FCommonAnalogCursor::RefreshCursorVisibility()

or FCommonAnalogCursor::ShouldHideCursor()

the the CommonUI Docs:

I created a custom FCommonAnalogCursor. It’s not specifically for solving the mouse display issue, but you can use it as a reference.