Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Using multiple control schemes not working with PlayerInput

Discussion in 'Input System' started by Iron-Warrior, Oct 21, 2019.

  1. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Hi, I'm trying to get PlayerInput to work with multiple control schemes (one for mouse/keyboard and one for Gamepad) and it doesn't seem to work. I'm using the script below:

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class InputTest : MonoBehaviour
    5. {
    6.     private void Start()
    7.     {
    8.         PlayerInput input = GetComponent<PlayerInput>();
    9.         input.actions["DoThing"].performed += DoThing_performed;
    10.     }
    11.  
    12.     private void DoThing_performed(InputAction.CallbackContext obj)
    13.     {
    14.         Debug.Log("CLICK!");
    15.         transform.position += Vector3.up;
    16.     }
    17. }
    When I have a single control scheme with DoThing mapped to the left mouse button, this works fine. When I create two control schemes (one called MKB and one called Gamepad) it does not work. The input debugger shows that the MKB scheme is selected for the player, but the events are not firing. Not sure if I'm doing something wrong. Tested in both 2019.1 and 2019.2, empty projects.
     
  2. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    If you are using 1.0.0 Preview it is broken you have to have preview-1 It was like that for everyone before they released the new package update last week.
     
  3. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Was able to get it working—I did not have any required devices on my control schemes, which I guess makes PlayerInput unable to correctly assign a control scheme.

    I was able to get it working on 0.9.5, so it either may have been a regression in 1.0.0, or you could be encountering a different issue.
     
  4. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    Oh no it was a bug that was introduced in 1.0.0 Preview that was fixed in 1.0.0 Preview 1. Glad you got it working though. Things like that should be labeled in the documentation so people who haven't used the Input System will know that.
     
    Iron-Warrior likes this.
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Just to confirm, yes, if there's control schemes in the actions, PlayerInput entirely goes by their device requirements. I've made a note that we should probably log a warning if there's no requirements present on the schemes.
     
    Iron-Warrior likes this.