Search Unity

Question Split Keyboard and Double Gamepad Help

Discussion in 'Input System' started by NateEdits, Nov 11, 2020.

  1. NateEdits

    NateEdits

    Joined:
    Jan 8, 2013
    Posts:
    1
    I have already set up a very scuffed way to split the keyboard using the new input system which I found while browsing the forums and the documentation. Here is what I currently have:

    Code (CSharp):
    1. private void Awake()
    2. {      
    3.      player1 = PlayerInput.Instantiate(playerPrefab, controlScheme: "player1", pairWithDevice: Keyboard.current);
    4.      player1.name = "player1";
    5.  
    6.      player2 = PlayerInput.Instantiate(playerPrefab, controlScheme: "player2", pairWithDevice: Keyboard.current);
    7.      player2.name = "player2";
    8. }
    9. //Sets GAME bindings
    10. public void SetGameBindings(GameplayInputActions inputActions, PlayerInput playerInput)
    11. {
    12.      if (playerInput.playerIndex == 1)
    13.      {
    14.          var bindingGroup = inputActions.controlSchemes.First(x => x.name == "Player1").bindingGroup;
    15.          inputActions.bindingMask = InputBinding.MaskByGroup(bindingGroup);
    16.                
    17.       }
    18.       else
    19.       {
    20.           var bindingGroup = inputActions.controlSchemes.First(x => x.name == "Player2").bindingGroup;
    21.           inputActions.bindingMask = InputBinding.MaskByGroup(bindingGroup);
    22.             }          
    23.         }

    Basically the player1 control scheme has the left side of the keyboard and Gamepad bindings while the player2 control scheme has the right side of the keyboard and Gamepad bindings.
    The split keyboard functionality works fine. The problem exists when using a Gamepad it controls both players. I would like 1 Gamepad to control 1 player or 2 Gamepads to control each player individually. What would be a good setup to ensure the following:

    0 Gamepads = split keyboard.
    1 Gamepad = Gamepad and split keyboard
    2 Gamepads = both use a Gamepad, 1 use a Gamepad and 1 use the keyboard, or split keyboard.

    Thank you in advance for any help!