Search Unity

Resolved (New Input System) PerformInteractiveBinding Not Working

Discussion in 'Input System' started by michaelpynes, Jan 5, 2022.

  1. michaelpynes

    michaelpynes

    Joined:
    Sep 12, 2019
    Posts:
    79
    I have a button with a script that contains an Action Reference. What I am trying to make happen is have the player click a button with a title for the input, change the input to what they selected, and display the new name for the input.
    Code (CSharp):
    1. [SerializeField] private InputActionReference actionToRebind;
    2.     private InputActionRebindingExtensions.RebindingOperation rebindOperation;
    3.  
    4.     public TextMeshProUGUI KeyBindButton;
    5.     public void RemapButtonClicked()
    6.     {
    7.         actionToRebind.action.Disable();
    8.         rebindOperation = actionToRebind.action.PerformInteractiveRebinding(0).WithControlsExcluding("Mouse").WithCancelingThrough("<Keyboard>/escape").OnMatchWaitForAnother(0.2f).Start()
    9.         .OnCancel(operation =>
    10.         {
    11.             actionToRebind.action.Enable();
    12.         })
    13.         .OnComplete(operation =>
    14.         {
    15.             //SetPref(prefs, actionToRebind.action.GetBindingDisplayString(0));
    16.             actionToRebind.action.Enable();
    17.             KeyBindButton.text = "[" + actionToRebind.action.GetBindingDisplayString(0).ToUpper() + "]";
    18.         });
    19.  
    20.     }
    This is the entire script. I know it is completing the OnComplete fuction because the KeyBindButton.text is being changed to the name of the key that I press. But, it just isn't actually changing the action in the Action Map. It's meant to call "RemapButtonClicked()" when I click on an ui button. The script instance is attached to the button that is correlated to the Action. The button for it is in a settings menu that can be accessed after pausing the game. There is code that sets the game's Time.timescale to 0.0f.


    These are the components on the button (at least the ones that aren't already assumed).
    Capture.PNG
    The "Key Rebind Test" is the name of the button shown.

    This is the action asset that contains the bindings.
    Capture2.PNG
    I have "Jump" expanded because that's the binding I'm trying to use. There isn't special with it, it's just a button action type.
     
  2. michaelpynes

    michaelpynes

    Joined:
    Sep 12, 2019
    Posts:
    79
    Alright, everyone. I figured out what the issue was. I was subscribing to the methods that would be called by the button presses in the script itself. Instead, I used the Player Input component and put the functions into those methods instead. That is what made all the code finally work.