Search Unity

How to setup user rebind-able Inputs for local multiplayer co-op game

Discussion in 'Input System' started by Diet-Chugg, Apr 17, 2019.

  1. Diet-Chugg

    Diet-Chugg

    Joined:
    Jul 4, 2012
    Posts:
    51
    I want to be able to set up multiple different player default inputs. For example
    1. Player 1
      1. Jump - Controller One - South Button
      2. Punch - Controller One - West Button
    2. Player 2
      1. Jump - Controller Two - South Button
      2. Jump - Controller Two - West Button
    From there I'd like to make an in-game UI where the players can re-bind the input so they could change it to something like this:
    1. Player 1
      1. Jump - Controller One - East Button
      2. Punch - Controller One - North Button
    2. Player 2
      1. Jump - Controller Two - West Button
      2. Punch - Controller Two - South Button
    EDIT: Looking at the docs here https://github.com/Unity-Technologi...Packages/com.unity.inputsystem/Documentation~
    It says "... create a UI to rebind input in my game?" //TODO

    So I guess I just need to wait until you have it ready.

    However, I still want to know how to set up controls for 4 player games. Do I need to have 4 action maps one for each player? (Basically create one and duplicate it 3 times and edit it for each player) Or create 4 InputActions scriptable objects and customize them for each player? Or create 4 control schemes. I'm really not sure. Is this another feature I need to wait for as it's not ready yet?

    I've watched a couple youtube videos to try to figure this out which have been great at covering one player controls that cannot be rebind-ed. (The one looked promising but ended up not covering it.)

    These are the ones I've found so far.
    https://www.youtube.com/playlist?list=PLKERDLXpXl_jLmqwzV45kmm8O0qezgcOz


    Anyone willing to point me in the right direction to solve this it would be awesome. :)
     
    tigerleapgorge likes this.
  2. pdjkleber

    pdjkleber

    Joined:
    Nov 21, 2013
    Posts:
    2
    I have the same doubt.
     
  3. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Recommendation for setting this up players is to use PlayerInput (some WIP docs exists here and here). It does, however, still has some problems and missing things that are being worked on.

    For setting things up manually, yes, each player will need a separate copy of the actions. One way is to just Instantiate() the action asset as needed. PlayerInput does that stuff automatically for you under the hood.

    For doing rebinding, UI support is indeed not done yet. The underlying functionality is mostly in place, though. For doing a rebind on one PlayerInput's actions, for example:

    Code (CSharp):
    1. playerInput.actions["gameplay/fire"].PerformInteractiveRebinding().Start();
    Various configuration options exist on the object returned by PerformInteractiveRebinding. A piece of code setting up a custom rebind can be found here (this one's for the "Listen" mode of the control picker in the editor UI which doesn't use actions directly but the principle is the same).
     
    ossetegames likes this.
  4. hummer_4x4

    hummer_4x4

    Joined:
    Feb 3, 2013
    Posts:
    25
    I use example StartListener();
    how apply editing bind ?

    Code (CSharp):
    1. .OnPotentialMatch(
    2.                 operation =>
    3.                 {
    4.                         // We never really complete the pick but keep listening for as long as the "Interactive"
    5.                         // button is toggled on.
    6.                         // Debug.Log(operation);
    7.                         operation.Complete();
    8.                         // Repaint();
    9.                     })
    10.             .OnCancel(
    11.                 operation =>
    12.                 {
    13.                     Debug.Log("Cancel");
    14.                         // Repaint();
    15.                     })
    16.             .OnApplyBinding(
    17.                 (operation, newPath) =>
    18.                 {
    19.                         // InputManager.Player.SetCallbacks((actions) => { actions = operation.selectedControl; });
    20.                         // Debug.Log(operation.selectedControl.path);
    21.                         // operation.action.Enable();
    22.  
    23.                         // Debug.Log(newPath);
    24.                         // This is never invoked (because we don't complete the pick) but we need it nevertheless
    25.                         // as RebindingOperation requires the callback if we don't supply an action to apply the binding to.
    26.                     });