Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Input.GetJoystickNames gives incorrect index with multiple controllers

Discussion in 'Editor & General Support' started by SnubbleJr, Aug 26, 2015.

  1. SnubbleJr

    SnubbleJr

    Joined:
    Dec 14, 2013
    Posts:
    2
    I do not know if this is a bug with the Xbox 360 controller drivers, or with Input.GetJoystickNames, but I fear it might be both.

    Connecting more than 5 360 controllers exhibits some unusual behaviour:



    1. Connecting up to 4 works as you would expect, and Input.GetJoystickNames works fine.

    2. When connecting the 5th controller, controller LED is active, but it is still recognised by windows and Unity, seems reasonable enough.

    3. Now, if any of the original 4 controllers disconnects, the 5th controller will automatically take the disconnected controller’s Joystick number, which is unusual, as normally controllers retain their number.

    4. Unity acknowledges the disconnection of the controller, but not the Joystick number change in the 5th controller.

    5. Furthermore, reconnecting the disconnected controller will assign it to the 5th joystick, but Unity will still have it identified as its original position in Input.GetJoystickNames, even though the 2 controllers have changed Joystick numbers.
    So, weird bug in 360 controller drivers, but also a weird bug in Input.GetJoystickNames not updating array position with joystick number beyond 4 360 controllers, any suggestions to how to work around this?
     
  2. grimmreefer

    grimmreefer

    Joined:
    Jan 15, 2015
    Posts:
    31
    Hy, i have the same problem. Could you find a solution till now?
     
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,549
  4. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,501
    Unity uses XInput internally for Xbox 360 controllers on Windows, which is why you're able to get distinct L/R axes (sometimes). XInput has a hard limit of 4 XInput controllers. There is no way around this problem. If you need to connect more than 4, you cannot use XInput for controlling them, which means your L/R triggers will be a shared axis and will cancel each other out when pressed together.

    You can't do this within Unity because it always uses XInput for these devices. If you want to support more than 4, you'll have to use a 3rd party system (or write your own) to get input from Direct Input or Raw Input. Check out Rewired in my sig which gives you the option to use or disable XInput and choose your choice of input sources. There's a free trial on the website also.