Class InputActionRebindingExtensions
Extensions to help with dynamically rebinding InputActions in various ways.
Namespace: UnityEngine.InputSystem
Syntax
public static class InputActionRebindingExtensions : object
Remarks
Unlike InputActionSetupExtensions, the extension methods in here are meant to be called during normal game operation, i.e. as part of screens whether the user can rebind controls.
The two primary duties of these extensions are to apply binding overrides that non-destructively redirect existing bindings and to facilitate user-controlled rebinding by listening for controls actuated by the user.
Methods
ApplyBindingOverride(InputAction, Int32, String)
Apply a binding override to the Nth binding on the given action.
Declaration
public static void ApplyBindingOverride(this InputAction action, int bindingIndex, string path)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to apply the binding override to. |
Int32 | bindingIndex | Index of the binding in bindings to which to apply the override to. |
String | path | Override path (overridePath) to set on the given binding in bindings. |
Remarks
Calling this method is equivalent to calling ApplyBindingOverride(InputAction, Int32, InputBinding) like so:
action.ApplyBindingOverride(new InputBinding { overridePath = path });
See Also
ApplyBindingOverride(InputAction, Int32, InputBinding)
Apply a binding override to the Nth binding on the given action.
Declaration
public static void ApplyBindingOverride(this InputAction action, int bindingIndex, InputBinding bindingOverride)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to apply the binding override to. |
Int32 | bindingIndex | Index of the binding in bindings to which to apply the override to. |
InputBinding | bindingOverride | A binding that specifies the overrides to apply. In particular, the overridePath, overrideProcessors, and overrideInteractions properties will be copied into the binding in bindings. The remaining fields will be ignored by this method. |
Remarks
Unlike ApplyBindingOverride(InputAction, InputBinding) this method will not use Matches(InputBinding) to determine which binding to apply the override to. Instead, it will apply the override to the binding at the given index and to that binding alone.
The remaining details of applying overrides are identical to ApplyBindingOverride(InputAction, InputBinding).
Note that calling this method with an empty (default-constructed) bindingOverride
is equivalent to resetting all overrides on the given binding.
// Reset the overrides on the second binding on 'fireAction'.
fireAction.ApplyBindingOverride(1, default);
See Also
ApplyBindingOverride(InputAction, String, String, String)
Put an override on all matching bindings of action
.
Declaration
public static void ApplyBindingOverride(this InputAction action, string newPath, string group = null, string path = null)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to apply the override to. |
String | newPath | New binding path to take effect. Supply an empty string to disable the binding(s). See InputControlPath for details on the path language. |
String | group | Optional list of binding groups to target the override
to. For example, |
String | path | Only override bindings that have this exact path. |
Remarks
Calling this method is equivalent to calling ApplyBindingOverride(InputAction, InputBinding) with the properties of the given InputBinding initialized accordingly.
// Override the binding to the gamepad A button with a binding to
// the Y button.
fireAction.ApplyBindingOverride("<Gamepad>/buttonNorth",
path: "<Gamepad>/buttonSouth);
See Also
ApplyBindingOverride(InputAction, InputBinding)
Apply overrides to all bindings on action
that match bindingOverride
.
The override values are taken from overridePath, overrideProcessors,
and overrideInteractions on bindingOverride
.
Declaration
public static void ApplyBindingOverride(this InputAction action, InputBinding bindingOverride)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to override bindings on. |
InputBinding | bindingOverride | A binding that both acts as a mask (see Matches(InputBinding))
on the bindings to |
Remarks
The method will go through all of the bindings for action
(i.e. its bindings)
and call Matches(InputBinding) on them with bindingOverride
.
For every binding that returns true
from Matches
, the override values from the
binding (i.e. overridePath, overrideProcessors,
and overrideInteractions) are copied into the binding.
Binding overrides are non-destructive. They do not change the bindings set up for an action but rather apply non-destructive modifications that change the paths of existing bindings. However, this also means that for overrides to work, there have to be existing bindings that can be modified.
This is achieved by setting overridePath which is a non-serialized property. When resolving bindings, the system will use effectivePath which uses overridePath if set or path otherwise. The same applies to effectiveProcessors and effectiveInteractions.
// Override the binding in the "KeyboardMouse" group on 'fireAction'
// by setting its override binding path to the space bar on the keyboard.
fireAction.ApplyBindingOverride(new InputBinding
{
groups = "KeyboardMouse",
overridePath = "<Keyboard>/space"
});
If the given action is enabled when calling this method, the effect will be immediate, i.e. binding resolution takes place and controls are updated. If the action is not enabled, binding resolution is deferred to when controls are needed next (usually when either controls is queried or when the action is enabled).
See Also
ApplyBindingOverride(InputActionMap, Int32, InputBinding)
Copy the override properties (overridePath, overrideProcessors,
and overrideInteractions) from bindingOverride
over to the
binding at index bindingIndex
in bindings of actionMap
.
Declaration
public static void ApplyBindingOverride(this InputActionMap actionMap, int bindingIndex, InputBinding bindingOverride)
Parameters
Type | Name | Description |
---|---|---|
InputActionMap | actionMap | Action map whose bindings to modify. |
Int32 | bindingIndex | Index of the binding to modify in bindings of
|
InputBinding | bindingOverride | Binding whose override properties (overridePath, overrideProcessors, and overrideInteractions) to copy. |
ApplyBindingOverride(InputActionMap, InputBinding)
Apply the given binding override to all bindings in the map that are matched by the override.
Declaration
public static int ApplyBindingOverride(this InputActionMap actionMap, InputBinding bindingOverride)
Parameters
Type | Name | Description |
---|---|---|
InputActionMap | actionMap | An action map. Overrides will be applied to its bindings. |
InputBinding | bindingOverride | Binding that is matched (see Matches(InputBinding)) against
the bindings of |
Returns
Type | Description |
---|---|
Int32 | The number of bindings overridden in the given map. |
See Also
ApplyBindingOverrides(InputActionMap, IEnumerable<InputBinding>)
Declaration
public static void ApplyBindingOverrides(this InputActionMap actionMap, IEnumerable<InputBinding> overrides)
Parameters
Type | Name | Description |
---|---|---|
InputActionMap | actionMap | |
IEnumerable<InputBinding> | overrides |
ApplyBindingOverridesOnMatchingControls(InputAction, InputControl)
For all bindings in the action
, if a binding matches a control in the given control
hierarchy, set an override on the binding to refer specifically to that control.
Declaration
public static int ApplyBindingOverridesOnMatchingControls(this InputAction action, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An action whose bindings to modify. |
InputControl | control | A control hierarchy or an entire InputDevice. |
Returns
Type | Description |
---|---|
Int32 | The number of binding overrides that have been applied to the given action. |
Remarks
This method can be used to restrict bindings that otherwise apply to a wide set of possible controls.
// Create two gamepads.
var gamepad1 = InputSystem.AddDevice<Gamepad>();
var gamepad2 = InputSystem.AddDevice<Gamepad>();
// Create an action that binds to the A button on gamepads.
var action = new InputAction();
action.AddBinding("<Gamepad>/buttonSouth");
// When we enable the action now, it will bind to both
// gamepad1.buttonSouth and gamepad2.buttonSouth.
action.Enable();
// But let's say we want the action to specifically work
// only with the first gamepad. One way to do it is like
// this:
action.ApplyBindingOverridesOnMatchingControls(gamepad1);
// As "<Gamepad>/buttonSouth" matches the gamepad1.buttonSouth
// control, an override will automatically be applied such that
// the binding specifically refers to that button on that gamepad.
Note that for actions that are part of InputActionMaps and/or InputActionAssets, it is possible to restrict actions to specific device without having to set overrides. See bindingMask and bindingMask.
See Also
ApplyBindingOverridesOnMatchingControls(InputActionMap, InputControl)
For all bindings in the actionMap
, if a binding matches a control in the given control
hierarchy, set an override on the binding to refer specifically to that control.
Declaration
public static int ApplyBindingOverridesOnMatchingControls(this InputActionMap actionMap, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
InputActionMap | actionMap | An action map whose bindings to modify. |
InputControl | control | A control hierarchy or an entire InputDevice. |
Returns
Type | Description |
---|---|
Int32 | The number of binding overrides that have been applied to the given action. |
Remarks
This method can be used to restrict bindings that otherwise apply to a wide set of possible
controls. It will go through bindings and apply overrides to
// Create two gamepads.
var gamepad1 = InputSystem.AddDevice<Gamepad>();
var gamepad2 = InputSystem.AddDevice<Gamepad>();
// Create an action map with an action for the A and B buttons
// on gamepads.
var actionMap = new InputActionMap();
var aButtonAction = actionMap.AddAction("a", binding: "<Gamepad>/buttonSouth");
var bButtonAction = actionMap.AddAction("b", binding: "<Gamepad>/buttonEast");
// When we enable the action map now, the actions will bind
// to the buttons on both gamepads.
actionMap.Enable();
// But let's say we want the actions to specifically work
// only with the first gamepad. One way to do it is like
// this:
actionMap.ApplyBindingOverridesOnMatchingControls(gamepad1);
// Now binding overrides on the actions will be set to specifically refer
// to the controls on the first gamepad.
Note that for actions that are part of InputActionMaps and/or InputActionAssets, it is possible to restrict actions to specific device without having to set overrides. See bindingMask and bindingMask.
// For an InputActionMap, we could alternatively just do:
actionMap.devices = new InputDevice[] { gamepad1 };
See Also
GetBindingDisplayString(InputAction, Int32, out String, out String, InputBinding.DisplayStringOptions)
Return a string suitable for display in UIs that shows what the given action is currently bound to.
Declaration
public static string GetBindingDisplayString(this InputAction action, int bindingIndex, out string deviceLayoutName, out string controlPath, InputBinding.DisplayStringOptions options = (InputBinding.DisplayStringOptions)0)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to create a display string for. |
Int32 | bindingIndex | Index of the binding in the bindings array of
|
String | deviceLayoutName | Receives the name of the InputControlLayout used for the
device in the given binding, if applicable. Otherwise is set to |
String | controlPath | Receives the path to the control on the device referenced in the given binding,
if applicable. Otherwise is set to |
InputBinding.DisplayStringOptions | options | Optional set of formatting flags. |
Returns
Type | Description |
---|---|
String | A string suitable for display in rebinding UIs. |
Remarks
The information returned by deviceLayoutName
and controlPath
can be used, for example,
to associate images with controls. Based on knowing which layout is used and which control on the layout is referenced, you
can look up an image dynamically. For example, if the layout is based on DualShockGamepad (use
IsFirstLayoutBasedOnSecond(String, String) to determine inheritance), you can pick a PlayStation-specific image
for the control as named by controlPath
.
var action = new InputAction();
action.AddBinding("<Gamepad>/dpad/up", groups: "Gamepad");
action.AddBinding("<Mouse>/leftButton", groups: "KeyboardMouse");
// Prints "A", then "Gamepad", then "dpad/up".
Debug.Log(action.GetBindingDisplayString(0, out var deviceLayoutNameA, out var controlPathA));
Debug.Log(deviceLayoutNameA);
Debug.Log(controlPathA);
// Prints "LMB", then "Mouse", then "leftButton".
Debug.Log(action.GetBindingDisplayString(1, out var deviceLayoutNameB, out var controlPathB));
Debug.Log(deviceLayoutNameB);
Debug.Log(controlPathB);
See Also
GetBindingDisplayString(InputAction, Int32, InputBinding.DisplayStringOptions)
Return a string suitable for display in UIs that shows what the given action is currently bound to.
Declaration
public static string GetBindingDisplayString(this InputAction action, int bindingIndex, InputBinding.DisplayStringOptions options = (InputBinding.DisplayStringOptions)0)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to create a display string for. |
Int32 | bindingIndex | Index of the binding in the bindings array of
|
InputBinding.DisplayStringOptions | options | Optional set of formatting flags. |
Returns
Type | Description |
---|---|
String | A string suitable for display in rebinding UIs. |
Remarks
This method will ignore active binding masks and return the display string for the given binding whether it is masked out (disabled) or not.
var action = new InputAction();
action.AddBinding("<Gamepad>/buttonSouth", groups: "Gamepad");
action.AddBinding("<Mouse>/leftButton", groups: "KeyboardMouse");
// Prints "A".
Debug.Log(action.GetBindingDisplayString(0));
// Prints "LMB".
Debug.Log(action.GetBindingDisplayString(1));
See Also
GetBindingDisplayString(InputAction, InputBinding, InputBinding.DisplayStringOptions)
Return a string suitable for display in UIs that shows what the given action is currently bound to.
Declaration
public static string GetBindingDisplayString(this InputAction action, InputBinding bindingMask, InputBinding.DisplayStringOptions options = (InputBinding.DisplayStringOptions)0)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to create a display string for. |
InputBinding | bindingMask | Mask for bindings to take into account. Any binding on the action not matching (see Matches(InputBinding)) the mask is ignored and not included in the resulting string. |
InputBinding.DisplayStringOptions | options | Optional set of formatting flags. |
Returns
Type | Description |
---|---|
String | A string suitable for display in rebinding UIs. |
Remarks
This method will take into account any binding masks (such as from control schemes) in effect on the action (such as bindingMask on the action itself, the bindingMask on its action map, or the bindingMask on its asset) as well as the actual controls that the action is currently bound to (see controls).
var action = new InputAction();
action.AddBinding("<Gamepad>/buttonSouth", groups: "Gamepad");
action.AddBinding("<Mouse>/leftButton", groups: "KeyboardMouse");
// Prints "A".
Debug.Log(action.GetBindingDisplayString(InputBinding.MaskByGroup("Gamepad"));
// Prints "LMB".
Debug.Log(action.GetBindingDisplayString(InputBinding.MaskByGroup("KeyboardMouse"));
See Also
GetBindingDisplayString(InputAction, InputBinding.DisplayStringOptions, String)
Return a string suitable for display in UIs that shows what the given action is currently bound to.
Declaration
public static string GetBindingDisplayString(this InputAction action, InputBinding.DisplayStringOptions options = (InputBinding.DisplayStringOptions)0, string group = null)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to create a display string for. |
InputBinding.DisplayStringOptions | options | Optional set of formatting flags. |
String | group | Optional binding group to restrict the operation to. If this is supplied, it effectively becomes the binding mask (see Matches(InputBinding)) to supply to GetBindingDisplayString(InputAction, InputBinding, InputBinding.DisplayStringOptions). |
Returns
Type | Description |
---|---|
String | A string suitable for display in rebinding UIs. |
Remarks
This method will take into account any binding masks (such as from control schemes) in effect on the action (such as bindingMask on the action itself, the bindingMask on its action map, or the bindingMask on its asset) as well as the actual controls that the action is currently bound to (see controls).
var action = new InputAction();
action.AddBinding("<Gamepad>/buttonSouth", groups: "Gamepad");
action.AddBinding("<Mouse>/leftButton", groups: "KeyboardMouse");
// Prints "A | LMB".
Debug.Log(action.GetBindingDisplayString());
// Prints "A".
Debug.Log(action.GetBindingDisplayString(group: "Gamepad");
// Prints "LMB".
Debug.Log(action.GetBindingDisplayString(group: "KeyboardMouse");
See Also
GetBindingForControl(InputAction, InputControl)
Return the binding that the given control resolved from.
Declaration
public static InputBinding? GetBindingForControl(this InputAction action, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An input action that may be using the given control. |
InputControl | control | Control to look for a binding for. |
Returns
Type | Description |
---|---|
Nullable<InputBinding> | The binding from which |
GetBindingIndex(InputAction, String, String)
Get the index of the first binding in bindings on action
that matches the given binding group and/or path.
Declaration
public static int GetBindingIndex(this InputAction action, string group = null, string path = null)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An input action. |
String | group | Binding group to match (see groups). |
String | path | Binding path to match (see path). |
Returns
Type | Description |
---|---|
Int32 | The first binding on the action matching the given group and/or path or -1 if no binding on the action matches. |
See Also
GetBindingIndex(InputAction, InputBinding)
Get the index of the first binding in bindings on action
that matches the given binding mask.
Declaration
public static int GetBindingIndex(this InputAction action, InputBinding bindingMask)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An input action. |
InputBinding | bindingMask | Binding mask to match (see Matches(InputBinding)). |
Returns
Type | Description |
---|---|
Int32 | The first binding on the action matching |
See Also
GetBindingIndex(InputActionMap, InputBinding)
Get the index of the first binding in bindings on actionMap
that matches the given binding mask.
Declaration
public static int GetBindingIndex(this InputActionMap actionMap, InputBinding bindingMask)
Parameters
Type | Name | Description |
---|---|---|
InputActionMap | actionMap | An input action map. |
InputBinding | bindingMask | Binding mask to match (see Matches(InputBinding)). |
Returns
Type | Description |
---|---|
Int32 | The first binding on the action matching |
See Also
GetBindingIndexForControl(InputAction, InputControl)
Return the index into action
's bindings that corresponds
to control
bound to the action.
Declaration
public static int GetBindingIndexForControl(this InputAction action, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | The input action whose bindings to use. |
InputControl | control | An input control for which to look for a binding. |
Returns
Type | Description |
---|---|
Int32 | The index into the action's binding array for the binding that |
Remarks
Note that this method will only take currently active bindings into consideration. This means that if the given control could come from one of the bindings on the action but does not currently do so, the method still returns -1.
In case you want to manually find out which of the bindings on the action could match the given control, you can do so using Matches(String, InputControl):
// Find the binding on 'action' that matches the given 'control'.
foreach (var binding in action.bindings)
if (InputControlPath.Matches(binding.effectivePath, control))
Debug.Log($"Binding for {control}: {binding}");
LoadBindingOverridesFromJson(IInputActionCollection2, String, Boolean)
Restore all binding overrides stored in the given JSON string to the bindings in actions
.
Declaration
public static void LoadBindingOverridesFromJson(this IInputActionCollection2 actions, string json, bool removeExisting = true)
Parameters
Type | Name | Description |
---|---|---|
IInputActionCollection2 | actions | A set of actions and their bindings, such as an InputActionMap, an InputActionAsset, or a C# wrapper class generated from an .inputactions asset. |
String | json | A string persisting binding overrides in JSON format. See SaveBindingOverridesAsJson(IInputActionCollection2). |
Boolean | removeExisting | If true (default), all existing overrides present on the bindings
of |
Remarks
void SaveUserRebinds(PlayerInput player)
{
var rebinds = player.actions.SaveBindingOverridesAsJson();
PlayerPrefs.SetString("rebinds", rebinds);
}
void LoadUserRebinds(PlayerInput player)
{
var rebinds = PlayerPrefs.GetString("rebinds");
player.actions.LoadBindingOverridesFromJson(rebinds);
}
Note that this method can also be used with C# wrapper classes generated from .inputactions assets.
See Also
LoadBindingOverridesFromJson(InputAction, String, Boolean)
Restore all binding overrides stored in the given JSON string to the bindings of action
.
Declaration
public static void LoadBindingOverridesFromJson(this InputAction action, string json, bool removeExisting = true)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to restore bindings on. |
String | json | A string persisting binding overrides in JSON format. See SaveBindingOverridesAsJson(InputAction). |
Boolean | removeExisting | If true (default), all existing overrides present on the bindings
of |
Remarks
void SaveUserRebinds(PlayerInput player)
{
var rebinds = player.actions.SaveBindingOverridesAsJson();
PlayerPrefs.SetString("rebinds", rebinds);
}
void LoadUserRebinds(PlayerInput player)
{
var rebinds = PlayerPrefs.GetString("rebinds");
player.actions.LoadBindingOverridesFromJson(rebinds);
}
Note that this method can also be used with C# wrapper classes generated from .inputactions assets.
See Also
PerformInteractiveRebinding(InputAction, Int32)
Initiate an operation that interactively rebinds the given action based on received input.
Declaration
public static InputActionRebindingExtensions.RebindingOperation PerformInteractiveRebinding(this InputAction action, int bindingIndex = null)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to perform rebinding on. |
Int32 | bindingIndex | Optional index (within the bindings array of |
Returns
Type | Description |
---|---|
InputActionRebindingExtensions.RebindingOperation | A rebind operation configured to perform the rebind. |
Remarks
This method will automatically perform a set of configuration on the InputActionRebindingExtensions.RebindingOperation based on the action and, if specified, binding. In particular, it will apply the following default configuration:
- WithAction(InputAction) will be called with
action
- The default timeout will be set to 0.05f seconds with OnMatchWaitForAnother(Single).
- Pointer delta and position as well as touch position and delta controls will be excluded with WithControlsExcluding(String). This prevents mouse movement or touch leading to rebinds as it will generally be used to operate the UI.
- WithMatchingEventsBeingSuppressed(Boolean) will be invoked to suppress input funneled into rebinds from being picked up elsewhere.
- Except if the rebind is looking for a button, escapeKey will be set up to cancel the rebind using WithCancelingThrough(String).
- If
bindingIndex
is given, WithTargetBinding(Int32) is invoked to target the given binding with the rebind.
Note that rebind operations must be disposed of once finished in order to not leak memory.
// Target the first binding in the gamepad scheme.
var bindingIndex = myAction.GetBindingIndex(InputBinding.MaskByGroup("Gamepad"));
var rebind = myAction.PerformInteractiveRebinding(bindingIndex);
// Dispose the operation on completion.
rebind.OnComplete(
operation =>
{
Debug.Log($"Rebound '{myAction}' to '{operation.selectedControl}'");
operation.Dispose();
};
// Start the rebind. This will cause the rebind operation to start running in the
// background listening for input.
rebind.Start();
RemoveAllBindingOverrides(IInputActionCollection2)
Restore all bindings in the map to their defaults.
Declaration
public static void RemoveAllBindingOverrides(this IInputActionCollection2 actions)
Parameters
Type | Name | Description |
---|---|---|
IInputActionCollection2 | actions | Collection of actions to remove overrides from. |
See Also
RemoveAllBindingOverrides(InputAction)
Remove all binding overrides on action
, i.e. clear all overridePath,
overrideProcessors, and overrideInteractions set on bindings
for the given action.
Declaration
public static void RemoveAllBindingOverrides(this InputAction action)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action to remove overrides from. |
See Also
RemoveBindingOverride(InputAction, Int32)
Remove any overrides from the binding on action
with the given index.
Declaration
public static void RemoveBindingOverride(this InputAction action, int bindingIndex)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action whose bindings to modify. |
Int32 | bindingIndex | Index of the binding within |
RemoveBindingOverride(InputAction, InputBinding)
Remove any overrides from the binding on action
matching the given binding mask.
Declaration
public static void RemoveBindingOverride(this InputAction action, InputBinding bindingMask)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | Action whose bindings to modify. |
InputBinding | bindingMask | Mask that will be matched against the bindings on |
Remarks
// Remove all binding overrides from bindings associated with the "Gamepad" binding group.
myAction.RemoveBindingOverride(InputBinding.MaskByGroup("Gamepad"));
RemoveBindingOverrides(InputActionMap, IEnumerable<InputBinding>)
Declaration
public static void RemoveBindingOverrides(this InputActionMap actionMap, IEnumerable<InputBinding> overrides)
Parameters
Type | Name | Description |
---|---|---|
InputActionMap | actionMap | |
IEnumerable<InputBinding> | overrides |
SaveBindingOverridesAsJson(IInputActionCollection2)
Return a JSON string containing all overrides applied to bindings in the given set of actions
.
Declaration
public static string SaveBindingOverridesAsJson(this IInputActionCollection2 actions)
Parameters
Type | Name | Description |
---|---|---|
IInputActionCollection2 | actions | A collection of InputActions such as an InputActionAsset or an InputActionMap. |
Returns
Type | Description |
---|---|
String | A JSON string containing a serialized version of the overrides applied to bindings in the given set of actions. |
Remarks
This method can be used to serialize the overrides, i.e. overridePath, overrideProcessors, and overrideInteractions, applied to bindings in the set of actions. Only overrides will be saved.
void SaveUserRebinds(PlayerInput player)
{
var rebinds = player.actions.SaveBindingOverridesAsJson();
PlayerPrefs.SetString("rebinds", rebinds);
}
void LoadUserRebinds(PlayerInput player)
{
var rebinds = PlayerPrefs.GetString("rebinds");
player.actions.LoadBindingOverridesFromJson(rebinds);
}
Note that this method can also be used with C# wrapper classes generated from .inputactions assets.
See Also
SaveBindingOverridesAsJson(InputAction)
Return a string in JSON format that contains all overrides applied bindings
of action
.
Declaration
public static string SaveBindingOverridesAsJson(this InputAction action)
Parameters
Type | Name | Description |
---|---|---|
InputAction | action | An action for which to extract binding overrides. |
Returns
Type | Description |
---|---|
String | A string in JSON format containing binding overrides for |
Remarks
This overrides can be restored using LoadBindingOverridesFromJson(InputAction, String, Boolean).