Switch Pro Controller is registered as Two Controllers at the same time (mixed A/B- and X/Y- events)

I am creating a game with local multiplayer support. Players can login by pressing the right trigger of their controller at any point.

My problem is, that Switch Pro Controllers seem to be recogniced as two controllers at once. Gamepad.all gives me a SwitchProControllerHID and a XInputController, even if only one Pro Controller is connected. Also e.g. if i press B, the SwitchProControllerHID will recognice the button south as pressed, the XInputController will say that button east is pressed. Other Buttons like triggers or the sticks will work on both similarly, despite the fact that i only have one physical controller connected.

Does anybody know why Unity thinks the Switch Pro Controller should also be an XInputController? Is there a way to determine, that both are the same controller? (they have differend deviceIds)
I tried to banthe XInputControllers device-ID, when a switch and a xinput controller try to login to the game at the same frame, but more often than not the input from the XInputControllers comes at least one frame later. So this is not feasable…

Thanks in Advance for any help :slight_smile:

Steam input is probably intercepting it and creating the XInputController.

Thanks for the answer. Steam is Not running (but installed). But nontheless i have to make it work also for users who have steam installed :wink: is there any way to recognice a virtual steam xinputcontroller or any ID or something, to find out that two Controllers are Actually the same physical Controller? Or how can i make use of the Pro Controller without being tricked by steam All the time?

Hi.

It’s not gonna help you, but I ran into the exact same problem with a PS4 controller.
My thread here: PS4 controller detected twice on 2022.2 - #5 by Ferrhoe

No solution so far, but at least I know that I’m not alone.

Can you tell me which version of Unity you are running ?
My problem is happening on 2022, and an older version of my project on 2020 doesn’t have it.

Still trying to find a solution, and none of the “ID or something” worked for me, to detect if a controller was fake or not.

Hey, thanks for the answer. I am on 2022 too and i also have an older Projekt thats does not have the Problem. I think the input System was still Experimental at that point. I will Look it up as soon as i can.

I’m also having an issue with Switch Pro gamepad on Windows 10 using Unity 2022.3.4f1 and Input System 1.6.1. When I connect Switch Pro gamepad, Unity sees it as two devices: XInputController and SwitchProControllerHID. This is very unconveniente, because now we get multiple inputs for our single player game and multiple onControlsChanged events on each input…

Anyone have any idea how this could be solved or what workaround could be used?

For your singleplayer-game, you might Cache the Initial Controller-ID and then only use Inputs from that specific Controller. But in that case the User can not switch his Controller ingame…

Yeah, I would like for the players to be able to switch controller seamlessly :frowning:

Might be useful for someone else. This ugly workaround at least lets keep using Switch Pro gamepad:

// We execute this code on `playerInput.onControlsChanged`
if (gamepad is UnityEngine.InputSystem.Switch.SwitchProControllerHID) {
    foreach (var item in Gamepad.all) {
        if ((item is UnityEngine.InputSystem.XInput.XInputController) && (Math.Abs(item.lastUpdateTime - gamepad.lastUpdateTime) < 0.1)) {
            Debug.Log($"Switch Pro controller detected and a copy of XInput was active at almost the same time. Disabling XInput device. `{gamepad}`; `{item}`");
            InputSystem.DisableDevice(item);
        }
    }
}

Was having the same issue with 2022.3.25 but your hack helps. thanks a lot

I just ran into this today. Switch pro inputs are causing XInput and SwitchPro inputs to be generated in 2023.2.5 as well. I’m surprised it’s still a bug. Does anyone from Unity read this forum?

Same Problem

Same problem. Seriously, it’s issue after issue with Unity’s “Input System”.

The UI overlaps everywhere too, making it almost impossible to navigate at times. You can imagine my disappointment when I looked up this issue and people were complaining about it over half a decade ago.

Honestly, the only reason I even use Unity is due to the job market. If I want any contracts as a freelancer, Unity is the way to go. If I could have it any other way, I’d never think about touching this engine.

Same problem for me in version 2022.3.12f1.
The same issue occurred with PS4/PS5 controllers and was resolved recently, but it persists for the Switch Pro controller…

What is the gamepad variable in the if statement in this scenario? OnControlsChanged seems to take a PlayerInput as a parameter but how do we get gamepad?

Figured it out. For anyone else coming here from Google! Note that the solution below is absolutely not production ready and the real solution will need to be addressed by Unity. For temporary purposes though, this should work most of the time but in a scenario where an Xbox controller and a Switch controller are connected at virtually near the same time, the genuine Xbox controller may be disabled instead.

// input is a PlayerInput type
input.onControlsChanged += OnControlsChanged;

// Callback method
private void OnControlsChanged(PlayerInput input)
{
    Gamepad gamepad = input.GetDevice<Gamepad>();
    if (gamepad is UnityEngine.InputSystem.Switch.SwitchProControllerHID)
    {
        foreach (var item in Gamepad.all)
        {
            if ((item is UnityEngine.InputSystem.XInput.XInputController) && (Math.Abs(item.lastUpdateTime - gamepad.lastUpdateTime) < 0.1))
            {
                Debug.Log($"Switch Pro controller detected and a copy of XInput was active at almost the same time. Disabling XInput device. `{gamepad}`; `{item}`");
                InputSystem.DisableDevice(item);
            }
        }
    }
}