Search Unity

How can I set a specific control scheme at runtime?

Discussion in 'Input System' started by stefankohl, Sep 25, 2019.

  1. stefankohl

    stefankohl

    Joined:
    May 30, 2014
    Posts:
    53
    Hi,

    I plan to use two different Gamepad control schemes based on the platform the game is running on. Control scheme "A" is the default scheme using "Gamepad" bindings, scheme "B" is a special scheme defined for the Nintendo Switch platform and has some action buttons flipped. For example, I defined an input action which is bound to "button south" (scheme "A") and "Button A (Switch)" (scheme "B"). The A-button also mapa to "button east".

    Now I need to disable the generic scheme "A" on the Switch platform in order to prevent the north/south/east/west buttons interfering with A/B/X/Y. I'm sure there is an easy way to do this, but I couldn't figure out how. Any ideas?
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Try something like

    Code (CSharp):
    1. myActionAsset.bindingMask = new InputBinding {groups = "MyControlSchemeName"};
     
    Atto2O likes this.
  3. stefankohl

    stefankohl

    Joined:
    May 30, 2014
    Posts:
    53
    Works like a charm, thank you!
     
  4. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    The api changed.

    Code (CSharp):
    1. PlayerInput.defaultControlScheme = "MyControlSchemeName";
     
  5. marijapopovic

    marijapopovic

    Joined:
    Nov 25, 2022
    Posts:
    2
    If anyone has problem with other solutions, this worked for me
    gameObject.GetComponent<PlayerInput>().SwitchCurrentControlScheme(controlSchemes[number], Keyboard.current);