Quick answer: Always call Dispose on the InteractiveRebindingOperation in both OnComplete and OnCancel. Disable the action during rebind so the same key that completes it doesn’t fire the action.
Player rebinds Jump to Spacebar. They cancel mid-rebind. Future Spacebar presses still trigger the rebind callback because the operation wasn’t disposed.
The Symptom
After cancelling a rebind, subsequent input still feeds into the cancelled operation. Or memory grows because operations stack up.
The Fix
private InputActionRebindingExtensions.RebindingOperation _rebind;
public void StartRebind(InputAction action, int bindingIndex)
{
action.Disable();
_rebind = action.PerformInteractiveRebinding(bindingIndex)
.WithControlsExcluding("Mouse")
.OnComplete(op => { FinishRebind(action); })
.OnCancel(op => { FinishRebind(action); })
.Start();
}
private void FinishRebind(InputAction action)
{
_rebind?.Dispose();
_rebind = null;
action.Enable();
}
Both Complete and Cancel paths call FinishRebind which Disposes and re-enables. No leaks.
UI Cancel Button
If the user clicks a Cancel button on the rebind UI, call _rebind.Cancel() programmatically. OnCancel fires; FinishRebind runs.
Verifying
Open profiler. Start and cancel rebinds repeatedly. Memory should stay flat. Without Dispose, RebindingOperation count climbs.
“Disable. Start. Dispose on Complete and Cancel. Re-enable.”
Related Issues
For OnScreenStick, see OnScreenStick. For control scheme switch, see control scheme.
Always Dispose. Both paths. No leaks.