Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feature Request Rebind with restricted device type list

Discussion in 'Input System' started by xXApOXx, Jan 19, 2023.

  1. xXApOXx

    xXApOXx

    Joined:
    Feb 9, 2015
    Posts:
    76
    Hi,

    I'm currently working on an UI that allow the user to rebind a keyboard input or a gamepad input for the same action. I overriden OnApplyRebinding to be able to listen to all inputs and manually compare my current action's bindings to the path received in order to rebind only the good one (by default Unity override all paths).

    The code works good but when If I press a mouse button, the rebind operation is triggered without rebinding anything and it completes instead of ignoring that device. I fixed the code by adding WithControlsExcluding("Mouse").

    But I'm not satisfied with that because if my user has per say a Joystick plugged, I need to add WithControlsExcluding("Joystick") and so on for every possible device I don't want.
    And I wish to be able to deactivate "Gamepad" rebinding at anytime so rather than excluding every possible devices, I would prefere a method to include a list of allowed devices.

    I'm aware of the WithExpectedControlType() but It doesn't work with an array of types so I can't expect both Keyboard & Gamepad in a single rebind operation. And I didn't manage to get it working even with only Gamepad anyway.

    Also excluding "Gamepad" doesn't work, you have to exclude a specific type of gamepad like "DualShock4GamepadHID".

    So I tried to workaround by getting every devices returned by InputSystem.devices and excluding the one I don't want in that list. That way I can compare "DualShock4GamepadHID" type to "Gamepad" type and it works but somehow excluding "FastKeyboard" (found when iterated in the devices list) when I don't want keyboard rebinding doesn't work. In that case I have to exclude "Keyboard" so it's not logical with the "DualShock4GamepadHID" not excluded with "Gamepad".

    So after all of that, I think it would be great to have a a way to simply ask for a specific list of devices allow in one rebind operation.

    Thx for reading :p
     
  2. xXApOXx

    xXApOXx

    Joined:
    Feb 9, 2015
    Posts:
    76
    I found another solution in my case that works fine: I check if I apply a rebind or not in OnApplyRebind callback. If not, in the OnComplete callback, I restart the rebinding operation.