Hello everyone,
I have a very simple local multiplayer game, each player uses only two keys and so I have 4 couples of keys each player can use in a single keyboard (P1 is A and D, P2 is J and L, P3 is the arrow keys, and P4 uses the numpad).
Everything works perfectly, and I decided to give the players some more options in regards to which controller the want to use (if you have 4 controllers or use Parsec everyone wouldn’t have to use the same keyboard).
I have a system which checks the input, recognizes that input as the player 1 if it’s A or D for example, and creates a new player in a specific spot on the scene.
Every player uses the same buttons on the controller (of course), so how can I tell my script that the controller was used by player one? How can I recognize which controller it was and how can I assign that controller to the player object afterward?
The Input System currently doesn’t support multiple users per one device. It only supports one user per device.
Disclaimer, I’m not in the front of Unity at the moment so I can’t double-check this, may it isn’t working, but worth a try, probably.
What you can try is to setup your action with all the bindings and add separate control schemes.
Then add separate PlayerInput component to all of your players with defined control schemes. It may work.
But if not, you also can at least read the current control scheme from the PlayerInput object and handle the situation manually.
Disclaimer: Im using input system just for typical polling(think stuff like IsKeyDown) to feed my own input state class for single player,so Im definetly not an expert or even experienced.
That out of the way,in that same convo linked above i see some people bypass the PlayerInput/PlayerInputManager and that’s probably what Id do as well.Koru for example has a good example there using InputUser.With a bit of googling you get to the InputSystem docs(these docs do seem to have a lot of useful info!): https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Users.InputUser.html
A small quote from the page(again i recommend just reading through what some of the classes there do)
So you can make your own abstraction at what level you want(check Rene-Damm’s message in that forum, his list of classes is very interesting and you can just google for them to get to the docs like with InputUser).
If youre using PlayerInput(which i assume is the quick way to get stuff set up) just google for it and the PlayerInputManager(again mentioned by Rene in that post,just read the entire msg you wont regret it,I know I didnt) and see how you can maybe just pair multiple users to the same keyboard as well.
Again, Im not experienced with the input system or even unity for that matter.
If it does(or doesn’t) work out,please do tell what youve used if its not too much trouble as its an interesting problem, and one which i assume others will have.Plus Im curious abt it.
Cheers