I’m having a very persistent issue in the project I’m working on where the XBox controllers will get ‘mixed up’ in unity. For example, the player with Controller 1(according to the light on the controller) will move Player 2’s character, but shoot for his own character.
Our input settings are set up so each player has his/her own set of inputs. We have a “Move_1” axis for player 1’s movement, set to only take input from Joystick 1, yet when Joystick 2’s thumbstick is moved it registers as “Move_1”. This problem only happens in Unity, and checking the controllers directly in Windows or even playing other games works fine.
I have verified and re-verified that the numbers correspond correctly, i.e. “Move_1” SHOULD only be accepting input from “Joystick 1”. However, it only accepts from “Joystick 2”.
The only ‘solution’ we have found is to unplug all the controllers, close down and restart unity, then plug the controllers in one-by-one and wait for each one to initialize and move his player around before pluging in the next one.
Anyone have any idea what could be causing this? Thanks in advance.
Hi, I realize this is an old post, but I still want to leave the documentation in case anyone (or myself in the future) has the same question.
The input manager has the Joy Num field. This works only for axes, not for buttons.
For buttons you have to write (without the quotes) “joystick [joystick #] button [button #]” in the “positive button” box
IMPORTANT - Unity doesn’t necessarily map joystick 1 to the first controller. So if you have your XBOX controller with the green light on the first position, it doesn’t necessarily mean that it will be mapped to joystick 1.
I found a solution to point 3, it’s definitely not the best but it does work:
first - map a lot of controllers in the input manager.
So you see that I have kHorizontal and also j1Horizontal, j2Horizontal (k for keyboard, j1 for joystick one etc).
Then you ask the user to press a button in order to know what controller he has in his hand and store that in a variable. I used a string:
public string controller; // I store this in the Player class
Then have a place where you ask the user to press start and check what button he pressed and store that information in the controller variable that we defined before:
controller = "k";
else if (Input.GetButton("j1Start"))
controller = "j1";
Then, when you need to get input, concatenate the controller variable to the name of the button like so:
rigidbody2D.AddForce(Vector2.right * speed * (Input.GetAxis(controller + "Horizontal"));
I’m sure there must be a better way, but this might get you going.
Hope it helps.
It’s quite simple but as usual Unity’s documentation is incomplete.
Looking at input manager you need to define correct value for “positive button”. It turns out that default “joystick button 1”, “joystick button 2” catch button 1 and 2 on any connected joystick.
If you need to receive input from i-th button on n-th joystick you should set “positive button” to “joystick n button i”
The field “Joy Num” is well… misleading.