Skip to content

Rebinding in runtime not saving to .inputactions #750

@FeikoJoosten

Description

@FeikoJoosten

The function RequestNewBinding() in the following code is triggered by an Unity UI button to rebind my input action:

private void Awake() {
    controls = new TestInputActions();
    controls.TestMap.TestBinding.performed += NewactionOnPerformed;
}

private void OnDestroy() {
    controls.TestMap.TestBinding.performed -= NewactionOnPerformed;
}

private void TestBindingOnPerformed(InputAction.CallbackContext callbackContext) {
    Debug.Log("Action performed");
}

public void RequestNewBinding() {
    InputAction actionToUse = inputActions.actionMaps[0].actions[0];
    rebindOperation = actionToUse.PerformInteractiveRebinding().WithRebindAddingNewBinding().Start();
}

Adding a rebind like this, will add the new binding to the InputActionsReference. However, it's only usable in play mode after forcing an update to the InputActionReference.

When I'm using the rebind without .WithRebindAddingNewBinding(). The rebind doesn't even seem to register at all.

Repro steps:

  1. Setup a simple InputAction with a button.
  2. Setup code similar to what I'm doing.
  3. Setup an Unity UI button which executes the code from step 2.
  4. Enter play mode and click the button.
  5. Press a new button for the binding to register.
  6. Exit play mode and re-open your InputActionReference asset.
  7. Notice a new binding has been added to your InputActionReference.
  8. Enter play mode and try executing TestBindingOnPerformed using your new button.
  9. Notice that the function does not execute, however your old binding still works (as intended because we use .WithRebindAddingNewBinding().
  10. Exit play mode and make a change to the InputActionReference asset (without removing your newly added bindings).
  11. Enter play mode and notice TestBindingOnPerformed now executes whenever you press your newly added binding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions