Joystick numbers 1 and 2 are swapped

I’m attempting to add Gamepad support to my game and have 4 xbox360 wireless controllers connected to my PC.
I’m using 1 input axis to listen to all joysticks for button 0 (A - Green button on xbox controllers).

Controller #1 (marked by green ring indicator) returns from Unity (4.2.1f4) that it is mapped to Joystick2Button0.
Controller #2 (also marked by the green ring) returns from Unity that it is mapped to Joystick1Button0.
Controller #3 (also marked by the green ring) returns Joystick3Button0… ← This is correct.
Controller #4 (also marked by the green ring) returns Joystick4Button0… ← This is correct.

Any idea why the first and second gamepad are mixed. I’ve tried the following debug steps so far:

  1. Restart unity.
  2. Disconnect and re-sync all controllers in desired order.
  3. Disconnect and try just 1 controller – Still says Joystick2Button0
  4. Restart computer and retry steps 1-3.

Is this a controller issue or a Unity input issue.

Here is the debugging code i used:

#pragma strict
function Update () {	
	if(Input.GetKey(KeyCode.Joystick1Button0)){
		print("One");
	} else if(Input.GetKey(KeyCode.Joystick2Button0)){
		print("Two");
	} else if(Input.GetKey(KeyCode.Joystick3Button0)){
		print("Three");
	} else if(Input.GetKey(KeyCode.Joystick4Button0)){
		print("Four");
	}
	
}

System specs:
Windows 7
Unity 4.2.1f4
4 wireless Microsoft Xbox360 controllers
1 Microsoft brand wireless reciever

The same thing is happening to me, i am using a ps3 controller.

No one knows how to fix this?

There’s no way to fix issues like this. Unity assigns joysticks to a joystick number based on some internal algorithm we have no control over. It’s very common to have a single joystick plugged in and have it mapped to a random joystick id such as 3. There’s very little predictable about Unity’s input system, especially with regards to joysticks. There is no way to fix a problem like this but to write your own wrapper around Unity input and try to remap controller ids in a way that you can use. Either that or go directly to the native input sources and start from scratch.

This problem (and many, many more) are the the reasons I wrote Rewired, which bypasses Unity’s input system and implements native input on many platforms for far more control over input. The idea behind Rewired is to give you a robust input system that is predictable and easily configurable for any type of game with any number of players on just about any platform. There’s a free trial link in my sig if you’re interested.