Search Unity

Get Current Control Scheme

Discussion in 'Input System' started by Danimita92, Dec 2, 2020.

  1. Danimita92

    Danimita92

    Joined:
    Jan 25, 2010
    Posts:
    32
    Hi there!
    I'm creating the tutorial texts for my game and I'd like them to update their icons depending on whether the player is using Mouse&Keyboard or a Gamepad. Problem is, how can I check which is the control scheme currently being used? I've read in other posts that the input system switches between them automatically. Awesome, but how can I see which one it's currently using?

    I have tried this:
    upload_2020-12-2_20-35-10.png

    But nothing comes up in the console when I hit buttons on the gamepad and then keyboard or viceversa.

    What am I missing here?
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    The onChange callback as shown in the docs says the event is triggered when the "InputUser setup in the system changes". I'm not exactly sure when that is, but I would assume it wouldn't fire just from hitting buttons on the Gamepad. One way to debug this issue is to just put another Debug.Log above the if statement, that way you can figure out whether or not ChangedControlScheme() is being called.

    I haven't used InputUsers before but reading through the docs it seems like you can acquire a user's control scheme at any point (as long as you have a reference to an InputUser) using exactly what you wrote in your method: inputUser.controlScheme. If you want to find a specific input user there appears to be a static property which has all of them in a list: InputUser.all. That should let you find the reference to the specific input user that you want. Be aware that I'm not quite sure what determines how the input user is associated with a control scheme, you may have to set it with ActivateControlScheme() if it ends up being null. Hope that helps a bit!

    EDIT: I'm seeing that you may be intending the control scheme to switch upon pressing input from another device. In that case I'm not sure what setup you're using or if it properly fires the event. Still, I'd recommend debugging further going up the chain until you find the breaking point.
     
  3. Danimita92

    Danimita92

    Joined:
    Jan 25, 2010
    Posts:
    32
    Thanks for your reply! Yeah, silly me I didn't realize you could/had to add a PlayerInput component to a gameobject to access its current control scheme. Now I'm checking for it in an update function and calling an event if it changes. Probably not the most efficient way of going around things but it does the job :D
     
    SomeGuy22 likes this.