PerformInteractiveRebinding not replacing old binding.

Hi there! I’m having trouble getting rebinding to work correctly and am hoping I’m making a mistake. I’m currently using V.1.2.0

  • I have some actions with some default bindings.

  • calling PerformInteractiveRebinding WILL create a new bind for an action.

  • it will not unbind the previous key. both keys will do the action.

  • if I save the binding overrides via SaveBindingOverridesAsJson, leave play mode, and then start the game again and apply them via LoadBindingOverridesFromJson, that will work - the old key is no longer functional.

Note that I even tried destroying the instance of my main Controls script (the object that inherits from IInputActionCollection2) and rebuilding it while in play mode, and that doesn’t fix the issue.

What am I missing?

PS: this is how I’m rebinding:

//"entry" is just a little gui button manager that has a reference to the InputAction.
entry.inputAction.Disable();
int keyboardIndex = entry.inputAction.GetBindingIndex(group: "Keyboard&Mouse");
               rebindOperation = entry.inputAction.PerformInteractiveRebinding()
                .OnComplete(operation => RebindComplete(entry, bindIndex))
                .OnCancel(operating => RebindCanceled(entry, bindIndex))
                .WithBindingGroup("Keyboard&Mouse")
                .OnMatchWaitForAnother(0.1f)
                .Start();

And RebindComplete looks like this:

void RebindComplete(UIRebindingEntry entry, int bindIndex)
    {
        rebindOperation.Dispose();
        entry.inputAction.Enable();
        rebindingFeedbackMenu.SetActive(false);
        entry.UpdateOnRebindComplete(bindIndex);
        PSInputs.OnBindingsUpdated();//saves the bindings to json.
        InputBinding[] bindings = entry.inputAction.bindings.ToArray();
        Debug.Log("finished rebinding this action: " + entry.inputAction.name);
        for(int i =0; i < bindings.Length; i++)
        {
            Debug.Log(bindings[i].path);
        }
    }

Also note that the above Debug.Log only displays the binding I set, which implies to me that the old binding should not be active…

Update, if anyone finds this. making some progress. Remembered that I could use this fantastic debugger that Unity added (duh)

8004992--1029527--upload_2022-3-29_16-42-42.png

looks like due to some part of my process, actions are being duplicated. the reason that quiting and reloading is fixing the issue is because it’s assigning the saved value twice.

UGH. found it. Another company made some changes to my code and removed a bool that prevented my input manager from being initialized multiple times.

The result is that my code was creating multiple instances of my main Controls class – that is, to be clear, the class that is generated by the Input System - the object that inherits from IInputActionCollection2. You know the one. I was creating an instance of it in my code so I could muck with it.

problem solved! Thanks me!

Oh, you’re very welcome.

1 Like