Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question [Noob question] Player Input Gets Separated

Discussion in 'Input System' started by Reimirno7, Jan 4, 2022.

  1. Reimirno7

    Reimirno7

    Joined:
    Nov 25, 2021
    Posts:
    36
    So I have two gameobjects A and B in the scene, each having a playerinput component with a separate action map attached. A is for real game player and B is a debug UI. So,
    • if I press Arrow key or use D pad of controller, I could move the player;
    • If I press space bar or A button of the controller, I could bring up a debug UI.
    Now everything works fine until I connects a controller in. Now one of the action map is paired to the controller, and the other is retained for keyboard. So,
    • Arrow key no longer works, only D pad works for moving the player;
    • A button no longer works, only space bar works for bringing up the UI.
    This is not what I want. What I want is you can use both keyboards and controller to trigger all actions, if both devices are connected. I am probably missing a very simple, basic thing here - what should I do?
     
  2. Reimirno7

    Reimirno7

    Joined:
    Nov 25, 2021
    Posts:
    36
    So I realized that this problem arises only because I abused the Player Input Component.

    This component, as its name suggests, seems to be designed to separate input from different players. It automatically detects the potential of local multiplayer and if there are many Player Input component alive it tries to distribute the different control devices among themselves as if there are many players.

    If I just want an action that is not associated with a player - that is, "global" - I should not be using a Player Input component. Instead I should just enable the action map and enable the action with a custom script that has reference to the input action asset.