Search Unity

PlayerInput Component not working with control schemes.

Discussion in 'Input System' started by viatech, Dec 16, 2019.

  1. viatech

    viatech

    Joined:
    Dec 6, 2017
    Posts:
    56
    Thought I would try out the PlayerInput component.....

    I have an example project using two players each with a PlayerInput component. If no control schemes are used in the InputActionAsset then devices (KB and Gamepad) bind to actions as expected (Keyboard to KB and XBox controller to Gamepad), but obviously you can't tell player1 input from player2. Fire is the Enter key or the RT trigger and produces a Debug.Log message.

    If you specify a Gamepad control scheme and then a KB control scheme in the InputActionAsset and bind one player to the Gamepad and one to the keyboard then, on play there is no binding between actions and devices, so you get no input at all. What I expected was one player using Gamepad input and one using KB.

    There are two scenes in the example project, one with control schemes one without. You will have to restart the editor if you change scenes or nothing will ever work - another bug perhaps?
     

    Attached Files:

  2. viatech

    viatech

    Joined:
    Dec 6, 2017
    Posts:
    56
    Further to this post.

    When you create a new control scheme there is a text box to add a scheme name and under that you can add a requirement. I had no idea what that was for so I left it out. It would seem that you HAVE to put the device requirement in there or the actions don't get associated with the input device.

    So for my Gamepad control scheme I added a "Gamepad" requirement and to the KB control scheme I added a "Keyboard" requirement, both with the "required" radio box option selected. Now the players get the correct controllers and actions, and inputs work as expected.

    REVIEW: Probably needs some UI code to prevent creating control schemes without giving the requirements - to stop my kind of idiot messing up!
     
  3. Euromancer

    Euromancer

    Joined:
    Aug 21, 2017
    Posts:
    11
    Thanks, solved my issue!
     
  4. viridisamor

    viridisamor

    Joined:
    Mar 1, 2019
    Posts:
    3
    I'm your kind of idiot. I spent an hour trying to figure out the issue. Finally found the right query to come across this post. Thanks for this! There really should be some message telling users to set a required device.
     
  5. RPowers

    RPowers

    Joined:
    May 14, 2015
    Posts:
    122
    This also fixed my issue thanks! Spend a couple hours trying to figure out why my keyboard wouldn't trigger actions. There really should be some UI or message to warn us that a control scheme needs a device requirement to work.
     
  6. chaozou2008

    chaozou2008

    Joined:
    Mar 13, 2015
    Posts:
    3
    thank you very match, solved my issue! waste a few hours to find why it did not work....
     
  7. qball13z

    qball13z

    Joined:
    Nov 30, 2013
    Posts:
    15
    Had no idea why everything was working fine until I realized the last thing I changed was adding schemes. Thanks to this post I'm all good now, Unity definitely needs to add a UI prompt or just set it by default!
     
    SparkesRS and spider0502 like this.
  8. visca_c

    visca_c

    Joined:
    Apr 7, 2014
    Posts:
    30
    this solved my issue, it's such easy thing to miss.
     
  9. BlenderBlaster

    BlenderBlaster

    Joined:
    Sep 22, 2014
    Posts:
    6
    Goodness gracious, another +1 on this issue. There really ought to be some kind of warning message or something to let you know that the Device Requirement needs to be checked. I just spent hours trying to track down why my inputs were not working, and this is probably the 20th thread I hopped in to and the only one with the answer I needed.
     
  10. spider0502

    spider0502

    Joined:
    Oct 4, 2021
    Posts:
    1
    Oh my god! I've spent 3 days on this including the time waiting for a new Xbox controller delivery.
     
    SparkesRS likes this.
  11. SparkesRS

    SparkesRS

    Joined:
    Jan 11, 2024
    Posts:
    6
    I just spent a few hours trying to figure this out. So many unrelated posts until I came across this thread. It always blows my mind when Unity features aren't good-to-go out-of-the-box, but you solved the problems for me!
     
  12. Damonya

    Damonya

    Joined:
    Sep 10, 2023
    Posts:
    4
    You are the best.

    I searched for hours, including with Copilot AI which sent me in hundreds of improbable directions ^^

    This is all the more important to know, as before I used the system with generated C# class and this was not necessary then. It only becomes mandatory with the PlayerInput component.
     
    Last edited: Apr 17, 2024