Search Unity

WithCancelingThrough("<Keyboard>/escape") also cancels with "<Keyboard>/e"

Discussion in 'Input System' started by Konaju-Games, Feb 1, 2022.

  1. Konaju-Games

    Konaju-Games

    Joined:
    Jul 11, 2012
    Posts:
    22
    Just the latest of many issues with the new Input System, I found today that specifying "<Keyboard>/escape" for cancelling an interactive rebinding operation will also cancel the rebinding operation if the user presses the E key on the keyboard, meaning that we cannot rebind the input action to E. Suspecting the system was matching the substring of "<Keyboard>/escape" with "<Keyboard>/e", I changed the cancelling key to "<Keyboard>/backspace". And pressing B on the keyboard now cancelled the rebind operation. Substring test confirmed.

    We're trying to use this for a commercial game, but I do not think that Input System, even at version 1.3.0, is ready for commercial use yet.
     
  2. Konaju-Games

    Konaju-Games

    Joined:
    Jul 11, 2012
    Posts:
    22
    Implemented a work-around. In the onComplete callback, check the candidates for the desired cancel inputs and cancel it ourselves.

    Code (CSharp):
    1.         bool canceled = operation.canceled;
    2.         if (!canceled)
    3.         {
    4.             // RebindingOperation has a bug where WithCancelingThrough("<Keyboard>/escape") matches
    5.             // "<Keyboard>/e" so it looks like have to do it manually
    6.             foreach (var candidate in operation.candidates)
    7.             {
    8.                 if (string.Compare(candidate.path, "/Keyboard/escape", ignoreCase: true) == 0
    9.                     || string.Compare(candidate.path, "/Gamepad/start", ignoreCase: true) == 0)
    10.                 {
    11.                     canceled = true;
    12.                     break;
    13.                 }
    14.             }
    15.         }
    16.         if (canceled)
    17.         {
    18.             Debug.Log("Rebind canceled");
    19.             inputAction.ApplyBindingOverride(bindingIndex, previousBinding);
    20.         }
    21.  
     
    MonolithBR likes this.
  3. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Fixed in upcoming 1.4.
     
  4. deadalusai

    deadalusai

    Joined:
    Dec 27, 2018
    Posts:
    8
    Any ETA for 1.4?

    Experiencing the same bug.
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Latest ETA is package on production server end of next week.
     
    ammarajam08 likes this.
  6. deadalusai

    deadalusai

    Joined:
    Dec 27, 2018
    Posts:
    8
    Great to know, thx!
     
  7. Mystical_Pidgeon

    Mystical_Pidgeon

    Joined:
    Jun 7, 2016
    Posts:
    8
    Any updates on this?
     
  8. hugeandy

    hugeandy

    Joined:
    Nov 2, 2016
    Posts:
    131
    Bump @Rene-Damm any updates about the release date? We are experiencing this bug as well
     
  9. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    Guessing it's held up in QA :|

    And yeah, I've had angry negative reviews about this too.
     
    RedHillbilly likes this.
  10. Mystical_Pidgeon

    Mystical_Pidgeon

    Joined:
    Jun 7, 2016
    Posts:
    8
  11. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    If anyone's looking for a gross solution in the meantime, override the cancel operation with total gibberish and manually handle in OnPotentialMatch:

    Code (CSharp):
    1.  
    2. ongoingRebind = action.PerformInteractiveRebinding(bindingIndex)
    3.     .OnPotentialMatch(operation => {
    4.       if (operation.selectedControl.path is "/Keyboard/escape") {
    5.          operation.Cancel();
    6.          return;
    7.        }
    8.    })
    9.    // bug which prevents binding to the `e` key...
    10.    // .WithCancelingThrough("<Keyboard>/escape")
    11.    .WithCancelingThrough("an enormous string of absolute gibberish which overrides the default which is escape and causes the above bug")
    12.  
     
  12. pheckinger

    pheckinger

    Joined:
    Jan 24, 2022
    Posts:
    5
    Similarly, I have had bad reviews and negative public comments because of this issue... it would be great to get a fix; and for unity to stop sitting on critical fixes for so long. Its not the first time I experienced this long of a delay for a fix and I am starting to question unity after using it for 10 years. :(
    The package system was supposed to stop this kind of update delay problems. It must be hard to work at unity when this keeps happening and something is slowing down or blocking them from making the product better in a reasonable way.
     
    Last edited: Jun 15, 2022
  13. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    @Rene-Damm

    Also stopping by to check on this issue, any news on a release? Also does it resolve all the issues with the name matching, as I'm pretty sure "a" matches "anyKey" and "r" matches "rightStick/up | rightStick/down | rightStick/left | rightStick/right"... and any other potential matches.
     
    jukibom likes this.
  14. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    The Pull Request #1492 shows this fix to be in ComparePathElementToString() so while I can't say for certain, it does appear to be a general case fix for those problems as well, yes.
     
    Razputin likes this.
  15. Mystical_Pidgeon

    Mystical_Pidgeon

    Joined:
    Jun 7, 2016
    Posts:
    8
    Thank you so much for this. Had some time to try it out and it appears to work perfectly. I've added a check for "/Gamepad/start" too since I have both controls bound with the same method.
     
    jukibom likes this.
  16. jukibom

    jukibom

    Joined:
    Aug 31, 2015
    Posts:
    54
    I should probably point out this should no longer be needed in the latest Input System 1.4.1 but I haven't upgraded yet so I can't say for certain.
     
  17. LuckedCoronet45

    LuckedCoronet45

    Joined:
    Feb 5, 2022
    Posts:
    4
    You are genius. Thank you so much
     
    jukibom likes this.
  18. JanBaaootbg

    JanBaaootbg

    Joined:
    Nov 13, 2020
    Posts:
    18
    @jukibom Thank you very much for the workaround!
     
  19. wengyhong

    wengyhong

    Joined:
    May 19, 2021
    Posts:
    7
    -
     
    Stephen1701 likes this.
  20. Stephen1701

    Stephen1701

    Joined:
    Mar 29, 2016
    Posts:
    132
    A year later and 1.4 still hasn't shown up in the package manager.
     
  21. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,336
    I just stumbled across this. I thought I was going insame (pressing E and getting cancel events).
    1.3 is still the default recommended version users will get through the package manager. Heck "<Keyboard>/escape" is even used in the documentation and tutorials.

    To be frank. This is worrying. How someone decided that a patch for something like this is not being backported (within a YEAR) to the version you ship in the package manager by default is beyond me.
     
    Last edited: Feb 6, 2023
  22. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    Disclaimer: I'm not involved in development of the Input System package, but here's what I saw:

    Input System 1.4.0 with that fix was released on April 10th 2022. Version 1.4.4 is currently the default release version in 2020 LTS and 2021 LTS.

    I'll assume you're using 2019 LTS (or even older), where 1.3.0 is still the verified version you'll end up by default.

    Please note that support for 2019 LTS already ended, so I wouldn't expect another fix release!

    To folks who, for some reason, have to still stick to the unsupported 2019 LTS: I'd try to upgrade to Input System 1.4.4, even if it's not verified. That's possible by expanding the package in the Package Manager and click "See all versions":

    upload_2023-2-6_12-54-35.png

    hth
     
    _geo__ likes this.
  23. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,336
    Thanks.

    To give a bit of background and why I find this lack of backporting problematic. I am using the 2020.3 release (so no 2019 or older). I do this because I am adding InputSystem Support to one of my Assets. Unity 2020 still is the min version for Asset Uploads and users expect it to be supported (~18% are still on 2020 according to Unitys on stats). I therefore can not switch to 2021 nor can I know which version they will use.

    While I understand the "you are using an old version and you should upgrade" logic, it simply is no option if you are dealing with an average Unity user. They will never do this:
    UnityInputVersion.gif
    Especially if the 1.3.0 version is the only one with the "verified" badge. For all practical purposes 1.4 and 1.5 do NOT exist until they are verified for older Unity versions. The gif was recorded in Unity 2020.3.30f1

    That's why I would strongly argue that someone (please) backports this patch into 1.3.0. Things like this make the life of an Asset Dev truely hard sometimes.

    And I also firmly believe that 1.3. should never have been shipped as it was. Recognizing Escape instead of E is just not something a INPUT system should do.

    *Sorry for the ranty nature of my post. I am just frustrated at the moment. <3
     
    Last edited: Feb 7, 2023
    Stephen1701 likes this.
  24. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,336
    For those who, like me, still need to support 1.3. I have extended jukiboms patch to be a bit more generic. It's a bit lengthy as it also supports multiple cancel paths.
    Code (CSharp):
    1. string[] abortControlPaths;
    2.  
    3. _rebindingOperation.OnPotentialMatch(operation =>
    4. {
    5.     if (InputSystem.version.CompareTo(System.Version.Parse("1.4.1")) < 0)
    6.     {
    7.         // We need a workaround for InputSystem < 1.4.1 due to this bug
    8.         // https://forum.unity.com/threads/withcancelingthrough-keyboard-escape-also-cancels-with-keyboard-e.1233400/
    9.         foreach (var cancelPath in abortControlPaths)
    10.         {
    11.             // Convert paths like "<Keyboard>/Escape" to "keyboard/escape".
    12.             string path = cancelPath;
    13.             if(path[0] == '<') path = "/" + path;
    14.             path = Regex.Replace(path, "[><{}*]+", "");
    15.             path = path.ToLower();
    16.  
    17.             string controlPath = operation.selectedControl.path.ToLower();
    18.  
    19.             // We'll only fix the diverging endings here.
    20.             // All other cases may still fail but the users should upgrade
    21.             // to InputSystem 1.4 anyways.
    22.             // If path ends with a long word (like ../escape) but controlPath
    23.             // ends short (like .../e) then ignore the comparison.
    24.             int controlPathIndex = controlPath.IndexOf("/");
    25.             int controlPathDelta = controlPath.Length - controlPathIndex;
    26.             int pathIndex = path.IndexOf("/");
    27.             int pathDelta = path.Length - pathIndex;
    28.  
    29.             if (Mathf.Abs(controlPathDelta - pathDelta) > 1)
    30.             {
    31.                 continue;
    32.             }
    33.  
    34.             if (InputControlPath.Matches(cancelPath, operation.selectedControl))
    35.             {
    36.                 _rebindingOperation.Cancel();
    37.                 break;
    38.             }
    39.         }
    40.     }
    41.     else
    42.     {
    43.         foreach (var cancelPath in abortControlPaths)
    44.         {
    45.             if (InputControlPath.Matches(cancelPath, operation.selectedControl))
    46.             {
    47.                 _rebindingOperation.Cancel();
    48.                 break;
    49.             }
    50.         }
    51.     }
    52. });
     
    Last edited: Feb 6, 2023
    Stephen1701 likes this.
  25. Stephen1701

    Stephen1701

    Joined:
    Mar 29, 2016
    Posts:
    132
    I
    am on Unity 2021.3.0f1 and I still only see Input System 1.3.0. Why can't I see a 1.4.4?
    upload_2023-2-6_20-12-47.png
    And I agree that by 1.3 you shouldn't have such a showstopping bug as E cancelling the bind when the ESC key is the one set.

    I am getting highly frustrated with things like this. I'm just trying to make games, but it seems I get stopped constantly with problems here there and everywhere. I don't have time to spend hours investigating all of these problems and ways around them, I'm trying to do this around my full time job, and my time and sanity just gets killed.

    Please send help!!!
    upload_2023-2-6_20-9-49.png
     
  26. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    @StephenW You need to update to (at least) Unity 2021.3.8.

    I'm curious, is there a particular reason you don't (try to) update to the latest patch release, which is recommended?

    Unity release versions adhere to Semantic Versioning. Therefore updating to the latest patch release will not break existing APIs or behavior. It usually incorporates fixes and minor changes (such as the package version bump you need).
     
    Stephen1701 likes this.
  27. Stephen1701

    Stephen1701

    Joined:
    Mar 29, 2016
    Posts:
    132
    Thanks. I didn't realise it wouldn't break anything, so I just left it alone. I try not to update anything unless I need to.

    I managed to install it by changing the manifest, but I guess I could install .8 as well.
     
  28. vycma

    vycma

    Joined:
    Feb 1, 2023
    Posts:
    3
    I am using 1.5 and with the following test code when pressing 'tab' (or anything else excluded), it binds the action to 'anyKey'. Is that a regression, or am I doing something wrong?

    Code (CSharp):
    1. private void RebindInteractively(InputAction action, int bindingIndex)
    2. {
    3. Debug.Log("Prebind: " + action.bindings[bindingIndex].effectivePath);
    4.            
    5. RebindingOperation rebind = action.PerformInteractiveRebinding(bindingIndex).WithControlsExcluding("<Keyboard>/tab");
    6.            
    7. rebind.OnComplete(r => { r.Dispose(); Debug.Log("Rebind:" + action.bindings[bindingIndex].effectivePath); });
    8.            
    9. rebind.Start();
    10. }
     
  29. vycma

    vycma

    Joined:
    Feb 1, 2023
    Posts:
    3
    Quick and dirty workaround for the 'anyKey' bug with similar shortcomings to the initial issue in this thread:
    Hook into rebind.OnPotentialMatch and filter out '/anyKey'. Rebinding will still complete, but not override the original path.
    Code (CSharp):
    1. rebind.OnPotentialMatch(r => WithControlsExcluding(r, "/anyKey"));
    2.  
    3. private RebindingOperation WithControlsExcluding(RebindingOperation rebind, string pattern)
    4. {
    5.     InputControlList<InputControl> candidates = rebind.candidates;
    6.  
    7.     for (int i = candidates.Count - 1; i >= 0; i--)
    8.         if (candidates[i].path.Contains(pattern))
    9.             rebind.RemoveCandidate(candidates[i]);
    10.  
    11.     return rebind;
    12. }
     
    Last edited: Mar 23, 2023
  30. VirtualDawn

    VirtualDawn

    Joined:
    Sep 15, 2014
    Posts:
    31
    I don't think I've ever upgraded a full unity version on a project without getting at least some errors. To be fair, they are usually minor, but still often something I couldn't resolve without our programmer.

    It is a bigger problem however when a (critical) plugin you are using hasn't updated and is blocking you from updating to newer unity version.

    Also, people would probably rather stick with one working unity version for the length of one project and only upgrade if absolutely necessary. For above mentioned reasons.
     
  31. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    What do you mean with "upgrade full unity version"? With semantic versioning you have a Major, Minor and Patch release (e.g. with 2021.3.21f the Major is 2021, Minor is 3 and Patch is 21).

    All I'm recommending is sticking with your chosen Major/Minor version and get the latest patch release. Developers put a LOT of effort into making sure that those patch updates don't break anything. I'd be surprised if your experience it vastly differently.

    In this case it's the exact other way around. You cannot update the package unless you update to the latest Unity patch release.

    I agree. But again, updating to a newer patch release has low risk of breaking stuff and IMHO is worth the upgrade if you get a fix you've been waiting for in a package.
     
  32. VirtualDawn

    VirtualDawn

    Joined:
    Sep 15, 2014
    Posts:
    31
    By full version I mean Major version update from, say Unity 2019.4.x to 2020.x.x or to the latest Unity LTS version. Of course, the newer Unity version you're using, the less problems you will get when updating through versions. 2019->2022 is quite a change and I don't really expect it to go smoothly.

    Oh yeah, if the new patch, or even a minor version, has a fix that you need then absolutely you should update. The risk is pretty much zero with version control and with minor releases nothing major(heh) usually breaks. However if I don't have problems, I rarely update versions mid project, but I do glance through the patch notes to see if there's something big. We might start updating the patches bit more frequently based on this conversation.
     
    tteneder likes this.
  33. unity_028AE3B1F1BC5DECE8AD

    unity_028AE3B1F1BC5DECE8AD

    Joined:
    Jul 31, 2022
    Posts:
    94
    thanks for this post, else I wouldn't have found the solution to this problem I was experiencing and racking my brain over. Can't believe this bug is still present a year later. Unity has more bugs than "A Bugs Life", more bugs than the amazon rain forest and more glitches than Metal Arms 2: Glitch in the system.

    Can't find any solution so now I must choose between players unable to bind the E key or being able to bind the escape key. Will have to go with the latter. 11/10 worth paying monthly for Unity Plus for.
     
    Last edited: Apr 29, 2023
  34. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    175
    Original post is from February 1st 2022 and the fix was released on April 10th 2022. I can't follow that argument.

    Multiple solutions have been proposed in this thread. Can you elaborate why none of them works for you?
     
    jukibom likes this.