Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Change bindings in realtime

Discussion in 'Input System' started by Gautzillaa, May 22, 2020.

  1. Gautzillaa

    Gautzillaa

    Joined:
    May 23, 2018
    Posts:
    6
    Hi everyone,

    I jumped into the new InputSystem lately as I wanted to add multiple controllers into my local multiplayer game.

    I want to add the ability for the players to change the keybinds as they wish. I created some schemes (one KB + one gamepad scheme per player), with the different actions used in my gameplay.

    I can access the different bindings by exploring the PlayerInput component of my players GameObjects:

    Code (CSharp):
    1. controls = GetComponent<PlayerInput>();
    2.         moveForward = controls.actions.FindAction("MoveForward");
    but I'm struggling to modify the bindings of these actions in realtime. Has anyone some easy way to do that?

    I'm not totally familiar with the new InputSystem yet so please don't hesitate to tell me if you think I'm doing the whole think wrong!

    Thanks!
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Code (CSharp):
    1. playerInput = GetComponent<PlayerInput>();
    2. moveForward = playerInput.actions["MoveForward"];
    3. moveForward.ApplyBindingOverride("<Gamepad>/dpad/right", group: "Gamepad");
    4. moveForward.ApplyBindingOverride("<Keyboard>/l", group: "KB");
    5.