Search Unity

Remove shortcut binding in code

Discussion in 'Editor & General Support' started by highlyinteractive, Jun 22, 2021.

  1. highlyinteractive

    highlyinteractive

    Joined:
    Sep 6, 2012
    Posts:
    116
    I'm trying to remove a shortcut from a menu item in Unity. I can successfully bind it to a different shortcut using this code:

    Code (CSharp):
    1. IShortcutManager manager = ShortcutManager.instance;
    2. KeyCombination combo = new KeyCombination(KeyCode.D, ShortcutModifiers.Shift);
    3. ShortcutBinding binding = new ShortcutBinding(combo);
    4. manager.RebindShortcut("Main Menu/Edit/Duplicate", binding);
    ...but I can't remove the shortcut.

    I've tried an empty KeyCombination or creating one with
    new KeyCombination(KeyCode.None, ShortcutModifiers.None)
    but that throws an exception.

    I've also tried
    ClearShortcutOverride("Main Menu/Edit/Duplicate");
    but that doesn't seem to do anything.

    I have a custom profile set up in the ShortcutManager and it's not readonly.

    I'm trying to remove the binding because I've built my own Duplicate function. Is there any way to remove a shortcut binding in code?

    Is there any other way to resolve a shortcut conflict in code?