Search Unity

Input System not working with keyboard using schemes

Discussion in 'Input System' started by ETGgames, Sep 17, 2019.

  1. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    101
    When I have no schemes at all in the input asset, I can have multiple action maps that have actions that use the keyboard just fine. Then I can attach separate player input scripts on different gameobjects, and assign them different default maps.

    However, as soon as I create a scheme with keyboard in the list, only one of the player input scripts works. the rest don't even show what scheme/device they are using in the debugger! It doesn't work whether I assign the schemes properly, or don't assign them a default scheme (leave it as <Any>), I can't get it to work no matter what!

    All I want is local multiplayer using the same keyboard. Arrows for one player, WASD for another.
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    You will need some manual code to set this up. The default behavior of the PlayerInput system is to assign one Input Device to each player - the use case being multiple gamepads for multiple players. It does this using Control Schemes, so it looks at the control schemes, and finds one matching the selected device, and will then turn that on. So, now your first player gets the Keyboard device, and your keyboard control scheme. If you add a second player, it will consider the Keyboard to already be used, and not assign the Keyboard device to the second player.

    But you can manually set up what you want. Try calling
    SwitchCurrentControlScheme("myWASDControlSchemeName", Keyboard.current)
    on one PlayerInput instance, and
    SwitchCurrentControlScheme("myArrowControlSchemeName", Keyboard.current)
    on the other one.
     
  3. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    101
    Surely it's not good to do that If I want to use the schemes at the same time.?
     
    Last edited: Sep 19, 2019
  4. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    101
    And also, even if I have both players using the name control scheme, it stops working for one of them. Only if there are no control schemes at all does it work.
     
  5. tv_Never

    tv_Never

    Joined:
    Nov 11, 2021
    Posts:
    11
    I've run into the same issue as this. Surely a second input should detect and assign the current input. Is there a way to toggle this off so that it can use the second players input.

    Assigning a players control would seem strange as I can't find anywhere where I can detect what input the person has

    My post is here: https://forum.unity.com/threads/mul...er-doesnt-get-auto-assigned-a-device.1416198/