Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Resolved PerformInteractiveBinding(0) Not Working

Discussion in 'Scripting' started by michaelpynes, Dec 28, 2021.

  1. michaelpynes

    michaelpynes

    Joined:
    Sep 12, 2019
    Posts:
    79
    I have a button with a script that contains an Action Reference.
    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 Method 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.
     
  2. Serge_Billault

    Serge_Billault

    Joined:
    Aug 26, 2014
    Posts:
    190
    This thread belongs to the Input System forum (https://forum.unity.com/forums/input-system.103/), and not really to the scipting forum.

    For one thing, if your rebindOperation reference is intended to be reseted with each call to RemapButtonClicked() you should not forget to call rebindOperation.Dispose() and set rebindOperation to null in the onCancel and onComplete callabacks.

    For another, if you have more than one action map, you didnt tell us if you checked that it is the correct one that was affected.

    Then, you are passing a hard coded binding index of '0' to PerformInteractiveRebinding(), and you didnt tell us if you checked that it was the correct binding index for that action that might have more than one binding.

    In other words you should provide more contextual infos to the people who will attempt to help you, like for exemple pictures of your action map/all your action maps, fully folded out, and circle the binding you are trying to change in your action map/one of these action maps.
     
  3. michaelpynes

    michaelpynes

    Joined:
    Sep 12, 2019
    Posts:
    79
    Alright, the hard 0 in the binding index is so that I can easily check for the only input in the action, and I am only using one action map. I'm kind of new to the new input system so I'm not very good with it so far.
     
  4. Serge_Billault

    Serge_Billault

    Joined:
    Aug 26, 2014
    Posts:
    190
    This should help people who will process your request to have a clearer view as to why it's not working for you.
     
  5. michaelpynes

    michaelpynes

    Joined:
    Sep 12, 2019
    Posts:
    79
    Alright, thanks for the assistance and guidance.
     
  6. 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.
     
unityunity