- Home /
Unity New Input System PerformInteractiveRebinding()
Does someone know why this code doesn't actually rebind the controls?
[SerializeField] private InputActionReference jumpAction = null;
[SerializeField] private GameObject startRebindObject = null;
[SerializeField] private GameObject waitingForInputObject = null;
private InputActionRebindingExtensions.RebindingOperation rebindingOperation;
public void StartRebinding()
{
startRebindObject.SetActive(false);
waitingForInputObject.SetActive(true);
rebindingOperation = jumpAction.action.PerformInteractiveRebinding()
.WithControlsExcluding("Mouse")
.OnMatchWaitForAnother(0.1f)
.OnComplete(operation => RebindComplete())
.Start();
}
private void RebindComplete()
{
ChangeUI();
rebindingOperation.Dispose();
startRebindObject.SetActive(true);
waitingForInputObject.SetActive(false);
}
It updates the UI just fine it also saves it between sessions (thanks to other parts of the code I didn't post because they work), but it doesn't actually change the bind. If I initially jump with "Space" and I change it so that I can jump with "O" it still jumps with "Space" and "O" still doesn't do anything.
Answer by Bumpalump · Apr 09, 2021 at 11:34 PM
I'll assume you're like me using this tutorial: https://www.youtube.com/watch?v=dUCcZrPhwSo
First thing you're missing is that you cannot perform PerformInteractiveRebinding() on key that is active so you'll need to either switch to Action map that doesn't have the key you're rebinding like:
playerController.SwitchCurrentActionMap("Menu");
or just disable the action
rebindAction.action.Disable();
You can Enable it / Switch Action map in your OnComplete function.
Now if that isn't the problem you're having there's another option. Try setting up your Player Input like this:
You probably used below code:
void Awake()
{
controls = new InputMaster();
controls.Gameplay.Tidy.performed += ctx => Tidy();
}
To hook a hotkey performed into the function. When it's done in Awake changing the hotkey afterwards doesn't seem to work but if you remove Awake code and just setup it as I've shown in screenshot in Invoke Unity Events mode it'll work just fine.