Class InputRebindOperation
Represents a single interactive rebinding session for one binding slot on a Unity Input System action, providing a fluent configuration API, conflict notification, and automatic action re-enabling upon completion or cancellation.
Implements
Inherited Members
Namespace: Scylla.Input
Assembly: ScyllaInput.dll
Syntax
public class InputRebindOperation : IDisposable
Remarks
Instances are created by StartRebind(string, int) and must
not be constructed directly. The internal constructor accepts only package-level
callers via the internal access modifier.
Lifecycle:
- StartRebind(string, int) creates the operation and calls Start() immediately. The action is disabled at this point to prevent it from responding to the input that will be used for rebinding.
-
The player presses an input. Unity's Input System invokes the internal
completion or cancellation callback, which sets IsActive to
false, re-enables the action, performs conflict detection, and fires OnComplete (and OnCancelled when applicable). - InputBindingManager receives the OnComplete callback, fires the manager-level events, disposes this operation, and clears its reference.
Fluent configuration: the following methods may be called on the returned operation before it receives input (they have no effect once the underlying Unity operation has completed):
- WithTimeout(float) - seconds to wait before auto-cancelling (default: 5 s).
- WithCancelingThrough(string) - input path that aborts the rebind (default:
<Keyboard>/escape). - WithControlFilter(string) - restrict accepted inputs to a specific device prefix.
- WithExpectedControlType(string) - restrict accepted inputs to a control type (e.g.,
"Button"). - WithExcludedPath(string) - exclude a specific input path from being selectable.
Conflict detection: after a successful rebind, the manager queries all registered action maps for any binding whose effective path matches the newly bound path (excluding the action being rebound). If conflicts are found, OnConflictDetected is fired before OnComplete. It is the caller's responsibility to resolve conflicts (e.g., by clearing the competing binding via ClearBindingOverride(string, int)).
Disposal: always disposed automatically by InputBindingManager after the operation completes. Manual disposal is safe but unnecessary in normal usage.
Properties
ActionID
Gets the name of the Unity Input System action whose binding is being modified.
Declaration
public string ActionID { get; }
Property Value
| Type | Description |
|---|---|
| string | The |
BindingIndex
Gets the zero-based index of the binding within the action's
bindings collection that this operation will replace.
Declaration
public int BindingIndex { get; }
Property Value
| Type | Description |
|---|---|
| int | A non-negative integer in the range |
DeltaPollingEnabled
Gets a value indicating whether mouse-delta polling is enabled for this
operation (equivalent to Mode == RebindMode.DeltaPolling).
Declaration
public bool DeltaPollingEnabled { get; }
Property Value
| Type | Description |
|---|---|
| bool |
DetectedModifiers
Gets the modifier keys that were held when the input was captured during a
modifier-aware rebind. Only valid after a successful completion with
ModifierSupportEnabled set to true.
Declaration
public ScyllaModifier DetectedModifiers { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaModifier |
IsActive
Gets a value indicating whether this rebind operation is currently listening for player input.
Declaration
public bool IsActive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Mode
Gets the rebind strategy this operation uses to capture input. See RebindMode for the available strategies.
Declaration
public RebindMode Mode { get; }
Property Value
| Type | Description |
|---|---|
| RebindMode |
ModifierSupportEnabled
Gets a value indicating whether modifier-aware keyboard polling is enabled
for this operation (equivalent to Mode == RebindMode.ModifierPolling).
Declaration
public bool ModifierSupportEnabled { get; }
Property Value
| Type | Description |
|---|---|
| bool |
NeedsPolling
Gets a value indicating whether this operation requires per-frame Update() calls by its owner (any custom polling mode).
Declaration
public bool NeedsPolling { get; }
Property Value
| Type | Description |
|---|---|
| bool |
NewPath
Gets the Unity Input System control path that was assigned after a successful rebind.
Declaration
public string NewPath { get; }
Property Value
| Type | Description |
|---|---|
| string | A non-null control path after a successful completion; |
OriginalPath
Gets the Unity Input System control path that was effective on the target binding immediately before this operation started.
Declaration
public string OriginalPath { get; }
Property Value
| Type | Description |
|---|---|
| string | A control path string (e.g., |
WasCancelled
Gets a value indicating whether the operation was cancelled before the player pressed a valid input.
Declaration
public bool WasCancelled { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
WasCleared
Gets a value indicating whether the player pressed the clear binding key during the rebind, requesting that the binding be removed (set to empty path).
Declaration
public bool WasCleared { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
WasSuccessful
Gets a value indicating whether the operation completed with the player successfully pressing a new input.
Declaration
public bool WasSuccessful { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
Cancel()
Programmatically cancels the active rebind session, triggering the cancellation callbacks and restoring the original binding path.
Declaration
public void Cancel()
Remarks
Delegates to the underlying Unity rebinding operation's Cancel method,
which asynchronously invokes the cancel callback registered in Start().
If the operation is not active (IsActive is false), a
warning is logged and the call is ignored.
Dispose()
Releases all resources held by this rebind operation, including the underlying Unity rebinding operation object.
Declaration
public void Dispose()
Remarks
If the operation is still active when Dispose is called, Cancel()
is invoked first. All event handlers (OnComplete,
OnConflictDetected, OnCancelled) are cleared to
prevent dangling references. Calling Dispose more than once is safe.
Start()
Begins the interactive rebinding session by disabling the target action and starting Unity's interactive rebinding operation with the configured parameters.
Declaration
public void Start()
Remarks
This method is called automatically by StartRebind(string, int);
callers do not need to invoke it manually on the returned operation. Calling it
a second time while IsActive is true logs a warning and
returns immediately without effect.
The target action is disabled for the duration of the session to prevent it from intercepting the input that should be bound. It is automatically re-enabled when the session ends, whether through success or cancellation.
After this method returns, IsActive is true and the
operation is waiting for input from the player.
Update()
Performs per-frame polling for any custom polling mode enabled on this operation
(modifier-aware keyboard polling or mouse-delta polling). Must be called each
frame while IsActive is true and NeedsPolling
is true.
Declaration
public void Update()
Remarks
Modifier mode reads Keyboard.current and Mouse.current directly
to detect key/mouse-button presses and modifier combinations. Three completion
scenarios are supported:
- Non-modifier key or mouse button pressed (with or without modifiers held): completes with key/button + modifiers.
- Modifier held, then released without pressing another key: completes with modifier key alone.
- Escape pressed or timeout elapsed: cancels the operation.
Delta mode reads Mouse.current.delta and completes with
<Mouse>/delta when the frame's movement magnitude exceeds
Scylla.Input.InputRebindOperation.DEFAULT_DELTA_POLLING_MAGNITUDE_THRESHOLD. Escape and clear-binding
keys are honored.
Has no effect when NeedsPolling is false or when
IsActive is false.
WithCancelingThrough(string)
Sets the Unity Input System control path that will cancel the rebind operation when pressed by the player.
Declaration
public InputRebindOperation WithCancelingThrough(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | A Unity Input System control path (e.g., |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
WithClearBinding(string)
Sets the Unity Input System control path that clears (unbinds) the binding when pressed during an active rebind session.
Declaration
public InputRebindOperation WithClearBinding(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | A Unity Input System control path (e.g., |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
WithControlFilter(string)
Restricts accepted inputs to controls on devices whose path starts with the given prefix, allowing rebinds to be scoped to a particular device class.
Declaration
public InputRebindOperation WithControlFilter(string devicePrefix)
Parameters
| Type | Name | Description |
|---|---|---|
| string | devicePrefix | A Unity Input System device path prefix (e.g., |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
WithDeltaMagnitudeThreshold(float)
Sets the minimum per-frame mouse-delta magnitude (in pixels) required to complete a delta-polling rebind. Only meaningful when WithDeltaPolling(bool) has been enabled.
Declaration
public InputRebindOperation WithDeltaMagnitudeThreshold(float pixels)
Parameters
| Type | Name | Description |
|---|---|---|
| float | pixels | Positive threshold in pixels. |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
Remarks
Lower values make the rebind more sensitive (completes on tiny cursor movements);
higher values require more deliberate motion to avoid false positives from tremor
or sensor noise. The default is 2.0 pixels. Values below 0 or above
a sanity ceiling are clamped to the default.
WithDeltaPolling(bool)
Enables or disables mouse-delta polling for this rebind operation. When enabled,
Start() skips Unity's interactive rebinding and instead uses per-frame
mouse-delta polling via Update() to capture <Mouse>/delta
when the player moves the mouse.
Declaration
public InputRebindOperation WithDeltaPolling(bool enabled)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
Remarks
When delta polling is enabled, the caller (or the
InputBindingManager) must call Update() each frame
while IsActive is true.
This mode exists because Unity's interactive rebinding does not reliably
capture <Mouse>/delta - a noisy, continuous Vector2 control -
even with WithoutIgnoringNoisyControls configured.
WithExcludedPath(string)
Adds a Unity Input System control path to the exclusion list, preventing the player from selecting it during this rebind session.
Declaration
public InputRebindOperation WithExcludedPath(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | A Unity Input System control path to exclude (e.g.,
|
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
WithExpectedControlType(string)
Restricts accepted inputs to controls of the specified Unity Input System control type, ensuring the bound control produces a value compatible with the action's expected data.
Declaration
public InputRebindOperation WithExpectedControlType(string type)
Parameters
| Type | Name | Description |
|---|---|---|
| string | type | A Unity Input System control type name such as |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
WithModifierSupport(bool)
Enables or disables modifier-aware keyboard polling for this rebind operation. When enabled, Start() skips Unity's interactive rebinding and instead uses per-frame keyboard polling via Update() to detect modifier+key combos (e.g., Shift+A, Ctrl+Shift+B).
Declaration
public InputRebindOperation WithModifierSupport(bool enabled)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled |
|
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
Remarks
When modifier support is enabled, the caller (or the InputBindingManager)
must call Update() each frame while IsActive is true.
After a successful rebind, DetectedModifiers contains the modifier flags that were held when the key was pressed.
WithTimeout(float)
Sets the maximum number of seconds the operation will wait for player input before automatically cancelling.
Declaration
public InputRebindOperation WithTimeout(float seconds)
Parameters
| Type | Name | Description |
|---|---|---|
| float | seconds | A positive value in seconds. The default is |
Returns
| Type | Description |
|---|---|
| InputRebindOperation | This operation instance, enabling method chaining. |
Events
OnCancelled
Raised when the operation is cancelled - either because the player pressed the configured cancel input path, the timeout elapsed, or Cancel() was called programmatically.
Declaration
public event Action OnCancelled
Event Type
| Type | Description |
|---|---|
| Action |
Remarks
This event is fired immediately before OnComplete (which will be
called with success = false). The original binding path remains in place
after cancellation.
OnComplete
Raised when the rebind operation terminates, regardless of whether the player successfully pressed an input or the operation was cancelled or timed out.
Declaration
public event Action<bool, string> OnComplete
Event Type
| Type | Description |
|---|---|
| Action<bool, string> |
Remarks
The two parameters are:
boolsuccesstrueif the player pressed a valid input and NewPath has been updated;falseif the operation was cancelled (by the cancel input, timeout, or programmatically via Cancel()).stringnewPathThe Unity Input System control path that was bound on success (e.g.,"<Keyboard>/space"), ornullon failure.
InputBindingManager subscribes to this event to perform cleanup and fire the manager-level events. After the manager's handler runs, the handler is unsubscribed and the operation is disposed.
OnConflictDetected
Raised after a successful rebind if one or more existing bindings share the newly assigned input path. Fired before OnComplete so that subscribers can resolve conflicts (e.g., clear competing bindings) before the binding manager propagates the completion.
Declaration
public event Action<IReadOnlyList<BindingConflict>> OnConflictDetected
Event Type
| Type | Description |
|---|---|
| Action<IReadOnlyList<BindingConflict>> |
Remarks
The argument is a non-null, read-only list of BindingConflict instances, one per colliding binding. The action being rebound is automatically excluded from the conflict scan.