Class InputBindingManager
Default implementation of IInputBindingManager that manages runtime input binding overrides, interactive rebinding operations, conflict detection, and per-profile persistence for the Scylla Input module.
Implements
Inherited Members
Namespace: Scylla.Input
Assembly: ScyllaInput.dll
Syntax
public class InputBindingManager : IInputBindingManager
Remarks
This class is created and owned by ScyllaInput. Consumers should depend on
the IInputBindingManager interface rather than this concrete type.
Storage: a PlayerPrefsBindingStorage is created automatically during Initialize(IInputActionManager, IInputContextManager) if no backend has been set via SetStorage(IBindingStorage). To use file-based storage, call SetStorage(IBindingStorage) with a JSONFileBindingStorage instance before or after initialization.
Auto-load: after initialization succeeds the manager checks
whether the "default" profile has saved data and, if so, loads it
automatically. Any failure during auto-load is caught and logged as a non-fatal
error so that the module continues to start up.
Event dual-dispatch: for each key operation (rebind started,
rebind completed/cancelled, bindings saved/loaded) the manager fires both a C#
event delegate (for tight UI coupling) and a Scylla SEX event published via
ScyllaEvents.Publish (for loose game-system coupling).
Serialization format: binding overrides are persisted as a JSON
object containing a version integer (1), the profile ID, a UTC ISO 8601
timestamp, and an array of override records (action name, binding index, override
path). Only actions whose binding differs from the InputActionAsset default
are included in the array.
Constructors
InputBindingManager()
Initializes a new InputBindingManager and sets the active profile to
the built-in "default" profile ID.
Declaration
public InputBindingManager()
Remarks
The manager is not yet operational after construction - call Initialize(IInputActionManager, IInputContextManager) to complete setup and attach it to an IInputActionManager.
Properties
CurrentProfileID
Gets the identifier of the currently active binding profile.
Declaration
public string CurrentProfileID { get; }
Property Value
| Type | Description |
|---|---|
| string | A non-null, non-empty string. Defaults to |
CurrentRebindOperation
Gets the InputRebindOperation that is currently waiting for player
input, or null if no rebind is active.
Declaration
public InputRebindOperation CurrentRebindOperation { get; }
Property Value
| Type | Description |
|---|---|
| InputRebindOperation | A non-null operation object while IsRebinding is |
IsInitialized
Gets a value indicating whether Initialize(IInputActionManager, IInputContextManager) has been called and completed successfully.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
IsRebinding
Gets a value indicating whether an interactive rebind operation is currently waiting for player input.
Declaration
public bool IsRebinding { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
CancelRebind()
Cancels the currently active rebind operation, restoring the original binding path
and firing the appropriate completion events with success = false.
Declaration
public void CancelRebind()
Remarks
This is a no-op if IsRebinding is false; a warning is logged
in that case. Internally delegates to
Cancel() on CurrentRebindOperation.
ClearBindingOverride(string, int)
Removes the runtime override from a specific action binding, reverting it to the
default path defined in the InputActionAsset.
Declaration
public void ClearBindingOverride(string actionID, int bindingIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of the action whose override should be cleared. Must not be null or empty, and must correspond to a registered action. |
| int | bindingIndex | Zero-based index of the binding from which to remove the override. Must be in the
range |
DeleteProfile(string)
Permanently removes the saved binding data for the given profile from the configured IBindingStorage backend.
Declaration
public void DeleteProfile(string profileID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | profileID | The non-null, non-empty profile ID to delete. A warning is logged and the call is
ignored if |
Remarks
This method does not change CurrentProfileID or modify the in-memory binding state. It only removes data from the storage layer.
ExportBindingsAsJSON()
Serializes all current binding overrides to a pretty-printed JSON string without writing to any storage backend.
Declaration
public string ExportBindingsAsJSON()
Returns
| Type | Description |
|---|---|
| string | A JSON string containing only the overridden bindings (actions using their default
path are omitted). The root object includes a version field, the current profile
ID, a UTC timestamp in ISO 8601 round-trip format, and an array of override
records. Returns |
Remarks
This method is the inverse of ImportBindingsFromJSON(string). The output is also the exact payload stored by SaveBindings(string).
GetAllProfiles()
Returns the identifiers of every profile for which the configured IBindingStorage backend has saved binding data.
Declaration
public IReadOnlyList<string> GetAllProfiles()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> | A non-null, read-only list of profile ID strings, or an empty list if no storage backend is configured or no profiles have been saved. |
GetBindingDisplayString(string, int)
Returns a human-readable display string for the specified binding, suitable for
showing in a key-mapping UI (e.g., "Space" for "<Keyboard>/space").
Declaration
public string GetBindingDisplayString(string actionID, int bindingIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of the action to query. Must not be null or empty, and must correspond to a registered action. |
| int | bindingIndex | Zero-based index of the binding to format. Defaults to |
Returns
| Type | Description |
|---|---|
| string | A localized display string generated by Unity's Input System, or |
GetBindingPath(string, int)
Returns the effective Unity Input System control path currently mapped to the specified binding, respecting any runtime override that has been applied.
Declaration
public string GetBindingPath(string actionID, int bindingIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of the action to query. Must not be null or empty, and must correspond to a registered action. |
| int | bindingIndex | Zero-based index of the binding within the action to query. Defaults to |
Returns
| Type | Description |
|---|---|
| string | A Unity Input System control path such as |
GetConflicts(string, string)
Returns all bindings across every registered action map whose effective path
matches path, optionally excluding one action by name.
When an IInputContextManager was provided during
Initialize(IInputActionManager, IInputContextManager), action maps belonging to contexts that share the same
ExclusionGroup as the excluded action's context are
also skipped, preventing false-positive conflicts between mutually exclusive
input modes.
Declaration
public IReadOnlyList<BindingConflict> GetConflicts(string path, string excludeActionID = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The Unity Input System control path to search for conflicts (e.g.,
|
| string | excludeActionID | An optional action name to exclude from the scan. Pass the ID of the action being
rebound so that its own existing binding is not reported as a conflict with itself.
Pass |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<BindingConflict> | A non-null, read-only list of BindingConflict instances describing
every binding that currently occupies |
HasBindingOverride(string, int)
Determines whether a runtime binding override is currently applied to the specified binding slot.
Declaration
public bool HasBindingOverride(string actionID, int bindingIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of the action to check. Must not be null or empty. |
| int | bindingIndex | Zero-based index of the binding to check. Defaults to |
Returns
| Type | Description |
|---|---|
| bool |
|
HasConflict(string, string)
Determines whether any binding currently occupies the given input path, optionally excluding one action from the check.
Declaration
public bool HasConflict(string path, string excludeActionID = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The Unity Input System control path to check (e.g., |
| string | excludeActionID | An optional action name to exclude. Typically set to the action being rebound so
its own current binding does not generate a self-conflict. Pass |
Returns
| Type | Description |
|---|---|
| bool |
|
HasSavedBindings(string)
Checks whether the configured IBindingStorage backend has saved binding data for the given profile.
Declaration
public bool HasSavedBindings(string profileID = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | profileID | The profile ID to check, or |
Returns
| Type | Description |
|---|---|
| bool |
|
ImportBindingsFromJSON(string)
Deserializes a JSON string previously produced by ExportBindingsAsJSON() and applies the contained overrides to the live action set.
Declaration
public void ImportBindingsFromJSON(string json)
Parameters
| Type | Name | Description |
|---|---|---|
| string | json | A non-null, non-empty JSON string in the format produced by ExportBindingsAsJSON(). If the string is malformed or cannot be parsed, an error is logged and no overrides are applied. |
Remarks
Before applying the imported overrides, all current in-memory overrides are cleared via ResetAllToDefaults() to guarantee a clean state. If an action named in the JSON is no longer registered, a warning is logged for that entry and processing continues with the remaining overrides.
This method does not fire OnBindingsLoaded or the corresponding SEX event - those are fired only by LoadBindings(string).
Initialize(IInputActionManager, IInputContextManager)
Initializes the binding manager with the given action manager, sets up the default storage backend if none has been configured, and attempts to auto-load the default profile from storage.
Declaration
public void Initialize(IInputActionManager actionManager, IInputContextManager contextManager = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IInputActionManager | actionManager | The IInputActionManager that the binding manager will use to resolve
action names, enumerate action maps, and apply or remove binding overrides. Must
not be |
| IInputContextManager | contextManager | Optional IInputContextManager used by GetConflicts(string, string) to
resolve ExclusionGroup relationships. When provided,
conflict detection skips bindings from action maps that belong to mutually exclusive
contexts (contexts sharing the same non-empty exclusion group). Pass |
Remarks
If SetStorage(IBindingStorage) has not been called before Initialize, a
PlayerPrefsBindingStorage is created automatically.
The manager then checks whether saved binding data exists for the
"default" profile and, if so, loads it automatically. Auto-load failures
(e.g., corrupt JSON) are caught, logged as errors, and treated as non-fatal;
initialization still completes and IsInitialized becomes
true.
Calling Initialize a second time while already initialized logs a
warning and returns immediately without re-initializing.
LoadBindings(string)
Reads previously saved binding data for the specified profile from the configured IBindingStorage backend and applies the overrides to the live action set.
Declaration
public void LoadBindings(string profileID = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | profileID | The profile slot to read from, or |
Remarks
Internally calls ImportBindingsFromJSON(string) which first calls ResetAllToDefaults() to clear any in-memory overrides before applying the stored ones. If the profile has no saved data the method logs an informational message and returns without modifying any bindings.
After successful application, OnBindingsLoaded and the SEX event InputBindingsLoadedEvent are fired.
ResetAllToDefaults()
Removes all runtime binding overrides from every action in every registered
action map, restoring each to the default path from the InputActionAsset.
Declaration
public void ResetAllToDefaults()
Remarks
Equivalent to calling ResetToDefaults(string) with a null
actionID. This is also called internally by
ImportBindingsFromJSON(string) before applying the imported overrides, to
ensure a clean slate.
ResetToDefaults(string)
Removes all runtime binding overrides from the specified action, or from all
registered actions when actionID is null or empty.
Declaration
public void ResetToDefaults(string actionID = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of a specific action to reset, or |
Remarks
This method delegates to ResetAllToDefaults() when
actionID is null or empty. Changes take effect immediately but
are not persisted; call SaveBindings(string) afterwards if the reset should
survive the session.
SaveBindings(string)
Serializes all current binding overrides to JSON and writes them to the configured IBindingStorage backend under the specified profile.
Declaration
public void SaveBindings(string profileID = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | profileID | The profile slot to write into, or |
Remarks
Only overrides are saved - actions that still use their default binding are not written. The JSON payload is produced by ExportBindingsAsJSON().
After a successful write, OnBindingsSaved and the SEX event InputBindingsSavedEvent are fired. If the manager is not initialized or no storage backend is configured, a warning is logged and the method returns without saving.
SetBindingOverride(string, int, string)
Programmatically applies a binding override to a specific action binding, bypassing interactive rebinding.
Declaration
public void SetBindingOverride(string actionID, int bindingIndex, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of the action to modify. Must not be null or empty, and must correspond to a registered action. |
| int | bindingIndex | Zero-based index of the binding to override. Must be in the range
|
| string | path | The Unity Input System control path to set as the override (e.g.,
|
Remarks
This method is useful for programmatic remapping (e.g., applying a saved preset) and does not fire rebind events. Changes take effect immediately on the underlying Unity action. Call SaveBindings(string) afterwards to persist the change.
SetCurrentProfile(string)
Changes the active profile without loading or saving any data.
Declaration
public void SetCurrentProfile(string profileID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | profileID | The non-null, non-empty profile ID to set as current. Call LoadBindings(string)
afterwards to apply the stored bindings for the new profile. A warning is logged
and the call is ignored if |
SetStorage(IBindingStorage)
Replaces the active IBindingStorage backend used for all subsequent save and load operations.
Declaration
public void SetStorage(IBindingStorage storage)
Parameters
| Type | Name | Description |
|---|---|---|
| IBindingStorage | storage | The new storage backend to use, or |
Remarks
Swapping the storage backend does not migrate previously saved data. If the manager has already auto-loaded a default profile, that data remains applied in memory; only future persistence operations are redirected to the new backend.
Shutdown()
Cancels any active rebind operation, releases all resources, clears all event
subscriptions, and resets IsInitialized to false.
Declaration
public void Shutdown()
Remarks
After Shutdown returns, the manager can be safely discarded. It cannot be
reused - a new instance must be created and initialized to resume binding
management.
StartRebind(string, int)
Creates and immediately starts an interactive rebind operation for the specified action binding, returning the operation object so the caller can configure it further or subscribe to its events.
Declaration
public InputRebindOperation StartRebind(string actionID, int bindingIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionID | The name of the Unity Input System action to rebind (e.g., |
| int | bindingIndex | Zero-based index of the binding within the action's |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | The newly created InputRebindOperation that is already listening for
input, or |
Remarks
The returned operation can be configured via its fluent API before calling Start() - however, this implementation starts the operation automatically. Callers may still chain fluent calls on the returned object to adjust the filter or cancel path while the operation is running; refer to InputRebindOperation for supported options.
Subscribing to OnRebindStarted or OnComplete is the recommended way to react to the outcome rather than polling IsRebinding.
Update()
Called once per frame by the owning ScyllaInput module. The default
implementation has no per-frame work; rebinding is driven entirely by Unity Input
System callbacks.
Declaration
public void Update()
UpdateRebind()
Performs per-frame update for the active rebind operation when modifier support
is enabled. Must be called each frame while IsRebinding is true.
Declaration
public void UpdateRebind()
Remarks
This method forwards to Update() on the CurrentRebindOperation. It has no effect when no rebind is active or when the active operation does not have modifier support enabled.
Events
OnBindingsLoaded
Raised after LoadBindings(string) successfully reads and applies binding data from the configured IBindingStorage backend.
Declaration
public event Action<string> OnBindingsLoaded
Event Type
| Type | Description |
|---|---|
| Action<string> |
Remarks
The string argument is the profile ID that was loaded. A corresponding SEX
event (InputBindingsLoadedEvent) is also published at the same time.
OnBindingsSaved
Raised after SaveBindings(string) successfully writes binding data to the configured IBindingStorage backend.
Declaration
public event Action<string> OnBindingsSaved
Event Type
| Type | Description |
|---|---|
| Action<string> |
Remarks
The string argument is the profile ID that was saved. A corresponding SEX
event (InputBindingsSavedEvent) is also published at the same time.
OnRebindCompleted
Raised when the active rebind operation terminates - either because the player pressed a valid input (success) or because the operation was cancelled or timed out (failure).
Declaration
public event Action<InputRebindOperation, bool, string> OnRebindCompleted
Event Type
| Type | Description |
|---|---|
| Action<InputRebindOperation, bool, string> |
Remarks
The three parameters carried by this event are:
- InputRebindOperationThe operation that completed. Its WasSuccessful and NewPath properties reflect the final state.
boolsuccesstrueif a new binding was recorded;falseif the operation was cancelled or timed out.stringnewPathThe Unity Input System control path that was bound (e.g.,"<Keyboard>/space"), ornullif the rebind was not successful.
A corresponding SEX event (InputRebindCompletedEvent or
InputRebindCancelledEvent) is also published to ScyllaEvents
at the same time.
OnRebindStarted
Raised immediately after a rebind operation has been created and started via StartRebind(string, int). The operation is listening for input at this point.
Declaration
public event Action<InputRebindOperation> OnRebindStarted
Event Type
| Type | Description |
|---|---|
| Action<InputRebindOperation> |
Remarks
A corresponding SEX event (InputRebindStartedEvent) is also published
to ScyllaEvents at the same time. Subscribers should use one or the other,
not both, to avoid double-handling.