Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Feedback WithCancelingThrough not accepting more than one binding

Discussion in 'Input System' started by BorjaFAC90, Aug 13, 2020.

  1. BorjaFAC90


    Jul 21, 2020
    Hi all,

    I've been using the new input system for a couple days or so, and I am just figuring out how should everything work. This time, I am facing a problem on my rebinding system. I support gamepad and keyboard, and when I use the PerformInteractiveRebinding function from the InputAction, I see that only the last WithCancelingThrough is the one that matters, as repeated calls to this will override the info (from the docs: Note that every rebind operation has only one such path. Calling this method repeatedly will overwrite the path set from prior calls). Any workaround in my case, where I want to have more than one possible cancel button (one for keyboard and the other for gamepad)?

    Szappy and CGDever like this.
  2. Szappy


    Feb 3, 2020
    Hey just wondering if you found a solution to this issue as I seem to have it
  3. Memoriesin8bit


    Feb 20, 2020
    @Szappy I ended up using a dirty little hack. Instead of using WithCancelingThrough, I intercepted certain cancel keys in the OnComplete call like this:
    Code (CSharp):
    1. if (action.bindings[bindingIdx].overridePath == "<Gamepad>/select" || action.bindings[bindingIdx].overridePath == "<Keyboard>/escape")
    2.             InputActionRebindingExtensions.ApplyBindingOverride(action, bindingIdx, new InputBinding{overridePath = ""});
    That way both the gamepad select as well as keyboard escape keys would immediately save the binding as empty.
  4. unity_06FC0E3D96180BDCC8ED


    Oct 30, 2021
    I wanted to add to this that if you use .WithControlsHavingToMatchPath("<Keyboard>") and have different key binding fields for keyboard and gamepad you can still use @Memoriesin8bit hack but you will have keyboard excluded for gamepad for instance. So in this case you can add .WithCancelingThrough("<Keyboard>/escape") to the rebindingOperation for your gamepad.