ApplyBindingOverride not working on non-composite bindings

I use this code to override my bindings.

// Override binding
InputBinding newBinding = bindings[i];
newBinding.overridePath = FormatControlPath(pressedControl.path);

Debug.Log($"Applying override from {bindings[i].effectivePath} to {newBinding.overridePath}");
action.ApplyBindingOverride(newBinding);

And it works. But only if the binding is part of a composite. Otherwise, the overridePath for the binding doesn’t change.

Even though Debug.Log outputs the correct path for both bindings that are part of a composite and those who aren’t.

?

Full script: Pastebin

Found the answer myself. Instead of the above code, I did this, and now it works as intended.


// Override binding for action
Debug.Log($"Applying override from {binding.effectivePath} to {FormatControlPath(pressedControl.path)}");

int bindingIndex = action.GetBindingIndex(path: binding.path);
action.ApplyBindingOverride(bindingIndex, FormatControlPath(pressedControl.path));

Output:

Applying override from <Keyboard>/q to <Keyboard>/c