Search Unity

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

Discussion in 'Input System' started by deshalb, May 26, 2023.

  1. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    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 :)
     
  2. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    Steam input is probably intercepting it and creating the XInputController.
     
  3. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    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 ;) 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?
     
  4. Ferrhoe

    Ferrhoe

    Joined:
    Jan 7, 2014
    Posts:
    15
    Hi.

    It's not gonna help you, but I ran into the exact same problem with a PS4 controller.
    My thread here: https://forum.unity.com/threads/ps4-controller-detected-twice-on-2022-2.1437199/#post-9022231

    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.
     
  5. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    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.
     
  6. zledas

    zledas

    Joined:
    Nov 3, 2010
    Posts:
    23
    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?
     
  7. deshalb

    deshalb

    Joined:
    Feb 22, 2013
    Posts:
    12
    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...
     
  8. zledas

    zledas

    Joined:
    Nov 3, 2010
    Posts:
    23
    Yeah, I would like for the players to be able to switch controller seamlessly :(
     
    Last edited: Jul 7, 2023
  9. zledas

    zledas

    Joined:
    Nov 3, 2010
    Posts:
    23
    Might be useful for someone else. This ugly workaround at least lets keep using Switch Pro gamepad:

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