Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

JoystickID Feature Request

Discussion in 'Input System' started by TheHighGround, Jul 10, 2018.

  1. TheHighGround

    TheHighGround

    Joined:
    Nov 19, 2017
    Posts:
    68
    Hello,

    Is it possible to have a more complex Device struct when it comes to input devices? For instance when I connect 2 controllers for example an Xbox One via USB (Index: 0) and a Ds4 via Bluetooth (Index: 1). The Input.GetJoystickNames() returns an array of size 2 with a name.

    If I unplug the Xbox One via USB (Index: 0) Input.GetJoysticksNames() returns an array of size 1 with just Ds4. So it's great that it tells me whats left. However, it doesn't tell me how Unity sees the device internally.

    Input.GetAxis("Joystick{AXIS_NUMBER_HERE}AxisX") is now invalid because if I go based on the Index of the array I am off by 1.

    Could there be a more complex way of returning how unity sees the JoystickNumber for the connected device? I feel if that feature is added it will solve all of Unity's problems when it comes to input because this is the actual issue. By doing this as a programmer I could make a basic check for hot-plugging knowing when a device is disconnected/reconnected.

    Going based on just the JoystickName is useless because it doesn't tell me how Unity sees it via InputManager. By this I mean JoyNum in Edit->Project Settings->Input->Horizontal (for example)->JoyNum. I want to know what JoyNum unity assigned to the connected controller so I can compensate for the changes when controllers are connected/disconnected.

    Yes I know of Rewired, InController etc etc...that's not what I am looking for. I want a way to control this myself.
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Heh yup, unfortunately GetJoystickNames() is a pretty poorly designed/implemented API. Which on top is inconsistent between platforms.

    Unfortunately, for the old input system, there are no plans to attempt fixing that at this point. The only way to do so is to either regress functionality somewhere in order to make things more consistent and more usable or to introduce an alternate API or probably find some other workaround. At this point, though, we've decided to fix things properly in the new input system instead. The old API just has so many issues and has native code spread across so many platforms that instead of trying to salvage the API we've decided to work on migrating to a new API.

    Sorry this probably isn't the answer you were hoping for :/
     
    FROS7 likes this.