Search Unity

Resolved How to disable input from other controllers (using PlayerInput)

Discussion in 'Input System' started by Twin-Stick, Jun 5, 2021.

  1. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
    Hey all,
    I am making a single player game using InputSystem with PlayerInput module.
    How do I have it so additional controllers do not send events?

    (Note; this is for Xbox GameCore but the same behaviour can be replicated on Windows).

    The situation is controller one is working as expected, but if a second controller is turned on - it will send input events as well.
    Ideally I'd like to be able to lock input to just one device.
     
    NeatWolf likes this.
  2. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
  3. Sam_Johns

    Sam_Johns

    Joined:
    Jul 15, 2015
    Posts:
    13
    Hi Twin-Stick,

    I was able to find this in the Input System guide, that answers a few of questions similar to this:
    https://docs.unity3d.com/Packages/c...anual/HowDoI.html#find-all-connected-gamepads

    I'm not sure if there is a cleaner way to do this, but you could do something like this:
    Code (CSharp):
    1. Gamepad[]
    2. gamepads = Gamepad.all;
    3.  
    4. for (int i = 0; i < gamepads.Length; i++)
    5. {
    6.     if (!gamepads[i].current)
    7.         InputSystem.DisableDevice(gamepads[i]);
    8. }
    9.  
    This should iterate through all of the connected Gamepads and disable those that aren't the main one.
    There is also a RemoveDevice() method, which removes the extra gamepads from the devices list, which you might be able to swap in for DisableDevice().

    I hope this helps!
     
    EDevJogos likes this.
  4. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
    I appreciate your reply.

    I suppose if I pair this with an ondevicechange event it may help with what I'm after.

    I'll dig into it a bit more.
     
  5. AmitloafTotes

    AmitloafTotes

    Joined:
    Jul 10, 2018
    Posts:
    26
    I need a solution for this. This is an XR issue so it's gonna prevent me for passing compliance.
     
  6. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
    Sam_Johns likes this.