Search Unity

Question Remove Binding Override !?

Discussion in 'Input System' started by Vagabond_, Apr 13, 2021.

  1. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    1,148
    Hi,

    i can not get this method "map.RemoveBindingOverrides(IEnumerable<InputBinding> overrides)" to work !

    The method "map.RemoveAllBindingOverrides();" works as expected and resets all the overrides, but we need to do it for specific bindings only !

    So, what would be the way to remove the override for specific binding in a "map" ?
     
    Last edited: Apr 13, 2021
  2. ThomasMoonKang

    ThomasMoonKang

    Joined:
    Aug 19, 2013
    Posts:
    7
    Hey Vagabond, just ran into the same issue as you.
    1. Update Input System in package manager.
    2. Remove and Re-add the asmdef for Unity.InputSystem and apply.
    It should show up after recompiling!
     
  3. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    165
    I figured I'd leave this here for anyone looking to remove a binding override.

    If you are trying to clear a binding override for a single action, setting it to the default binding in your InputActions asset, get the binding index, then pass it into...
    Code (CSharp):
    1. actionToRebind.RemoveBindingOverride(bindingIndex);
    2. actionToRebind.SaveBindingOverride(bindingIndex);
    If you want to clear all bindings for that action, including the default binding, get the binding index, then pass it into...
    Code (CSharp):
    1. actionToRebind.ApplyBindingOverride("<Gamepad>", "Gamepad", actionToRebind.bindings[bindingIndex].path);
    2. actionToRebind.SaveBindingOverride(bindingIndex);
    This assumes the control scheme that you want to clear is for the Gamepad. If it's Keyboard, Mouse, etc, just pop that in there. This is applying an "empty" binding override to the action that overrides the default binding.

    Be sure to look at the different method overloads for RemoveBindingOverride and ApplyBindingOverride to see which option suits your use case best.
     
    Ryiah likes this.