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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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:
    645
    The api changed.

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