- Home /
Multiple Local Controllers getting messed up.
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.
Hello, Did you find a solution for this? I have basically the same problem, but for me it works in the editor but not in the built game.
Unfortunately, no, I have not found the solution. It's at least somewhat comforting to know that I'm not the only person with this problem, at least.
At this point I'm seriously considering writing my own independent input manager with C# just to get around the problem.
Find a solution? I'm new to unity, and have just started working on a game that uses 4 players, set up similarly to yours (each player has their own axis and button set up in the input manager). No matter what I do, even when I restart Unity, or the Exe I've created, AND restarted my Xbox 360 wireless dongle AND the four controllers, I only have like a 50% chance that it will work properly..
Unfortunately not. I have since moved on to another project, but if you do find a solution I would love to hear about it!
Answer by The_Spellmaker · Nov 02, 2014 at 06:41 AM
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.
1) The input manager has the Joy Num field. This works only for axes, not for buttons.
2) For buttons you have to write (without the quotes) "joystick [joystick #] button [button #]" in the "positive button" box
3) 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:
if (Input.GetButton("kStart"))
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:
void Update()
{
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.
Cheers,
Spellmaker
I hate to be that one guy that revives old threads, but thanks. This helped me a lot--first time learning controller support. By the way, this works with PS4 controllers. I'm not sure about Xbox One but I'd guess it's the same.
We appreciate feedback as long as it's more than a "thanks" ^^. Don't forget to vote. $$anonymous$$eep in $$anonymous$$d you can upvote the answer but also the question (and even comments). A lot people here on UA don't vote at all. $$anonymous$$ost who do vote, forget to vote the question as well. Without the question there wouldn't be an answer.
So if you see a good / helpful post (question, answer, comment) you should upvote them. Be careful with downvotes though. Downvoting should only be used when there's misinformation in a post. If you downvote you should leave a comment and explain what's wrong. If you downvote a post you as well as the post author will loose some karma.
oh my god, thank you! I must've been trying to figure out what I did wrong for 2 hours! I thought there was something wrong with the script instances, because I configured the buttons just as I did for the axis(es?)
O$$anonymous$$G... two days of life could have been saved by this. Thanks.
Answer by kefrens · Dec 15, 2013 at 11:50 PM
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. :-)
We did that for the buttons. Unfortunately the problem we're having is with the axis, which don't use the button field.
$$anonymous$$y problem was with the trigger axis on a 360 controller. They are supposed to be the 9th and 10th axis. But with that setting they got messed up in my builds. However if Im using the 3rd axis, one trigger goes from 0-1 and the other -1 to 0. Then it works as it should.
motorn's solution works. It is still an issue in 2018. I wonder how i could use both triggers at once. If left-trigger "subtracts" and right-trigger "adds" the resulting Input is 0.
Your answer
Follow this Question
Related Questions
Getting Raw Joystick Input via Script 1 Answer
Controlling MouseLook script with keys/joystick 1 Answer
First Person Controller Erratic 1 Answer
Unity ignoring joysticks of specified number 0 Answers
Controller input not working correctly 0 Answers