Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Keyboard Multiplayer

Discussion in 'Input System' started by LittleDirge, Apr 25, 2021.

  1. LittleDirge

    LittleDirge

    Joined:
    Dec 3, 2018
    Posts:
    6
    Hello all, I'm working on a project for university that is largely working with local co-op. We've gotten multiplayer working for everything as long as all players have a unique device (i.e. keyboard, gamepad, etc) but we were looking for a solution to two players on one keyboard and not sure how the input system handles things. My question is how we best go about this. So far we've considered creating two custom input devices and define the controls as the keyboard buttons we want for those devices and overriding the HID fallback in order to define the keyboard differently. I think that the latter would also require us creating a custom input device, but we're still pretty green with the input system and not really sure what the best solution is or how to get more familiar with how it works.

    At the moment, we're really wading into unknown territory with the new input system and trying to learn as much about it as we can so we can use it more fully going forward, so any advice, ideas, or opinions would be greatly appreciated.
     
  2. LittleDirge

    LittleDirge

    Joined:
    Dec 3, 2018
    Posts:
    6
    Bump for a solution. This was actually an easier solve once I started learning a bit more about the Input System. The way to do this for us was to create separate control schemes within our action map for the various types of controls we needed (in this case, WASD and IJKL controls for the same keyboard) and leaving both control schemes as "Keyboard Optional".

    After we created our objects containing our PlayerInputs, we checked to see which keys were pressed and manually joined players to the game and then assigned the control schemes and the device to Keyboard.current for both sets of controls, we were able to get what we were looking for.
     
  3. FALLENxGaLaXie5

    FALLENxGaLaXie5

    Joined:
    Dec 15, 2015
    Posts:
    10
    Hey, so I’m doing pretty much the exact same thing (local co op with multiple controllers and trying to get multiple people on a keyboard as well), and curious if you could possibly go a little more in depth on how you did this?

    I’ve got two different control schemes for the keyboard (WASD, Arrow keys for me). From there I’m a little more lost and am having trouble finding documentation on getting this to work; I can spawn everything using the default “Join Player on Button Press” in the PlayerInputManager. So I’m assuming you need to use the manually join player option? Is this a callback or function you call on the PlayerInputManager? And then how did you check which control scheme was being used and assign it? Essentially I’m totally lost on the whole second paragraph of your solution haha; I’m admittedly fairly new to the new input system, and to be honest the documentation hasn’t seemed crazy robust to me so far, so any code you could throw my way would be much appreciated.

    Thanks!
     
  4. LittleDirge

    LittleDirge

    Joined:
    Dec 3, 2018
    Posts:
    6
    upload_2021-5-24_10-11-2.png

    Excuse the code for the moment, this is stand in as we're kinda in the middle of a transition. We set up a prefab for our PlayerInputManager to create, then set it to manually joining players. This code here was how we hardcoded the controls early on, but you could really set this up however you want.