InteractionInput

Individual input binding that wraps a Unity InputActionReference and manages a list of callbacks. When bound, it subscribes to the configured phase of the Unity input action and invokes all registered callbacks when that phase fires.

Definition

Namespace: Paragon.Townskeep.InteractionSystem Assembly: Townskeep.dll

[Serializable]
public class InteractionInput

Remarks

Each InteractionInput represents a single named input slot within an InteractionInputTable. It bridges the gap between the Interaction System's callback model (simple Action delegates) and Unity's Input System (which requires Action<InputAction.CallbackContext>).

The class manages its own subscription lifecycle: Bind() subscribes the internal handler to the appropriate Unity InputAction phase event, and Unbind() removes it. When triggered, it iterates callbacks in reverse order — this is a safety pattern that allows callbacks to remove themselves during invocation without index corruption.

The InputActionReference and InteractionInputPhase are configured in the Inspector. Callbacks are registered programmatically by InteractionInputTable during reflection-based discovery.

Quick Lookup

Goal
How

Add a callback

interactionInput.AddCallback(myAction)

Remove a callback

interactionInput.RemoveCallback(myAction)

Clear all callbacks

interactionInput.ClearCallbacks()

Subscribe to Unity input

interactionInput.Bind()

Unsubscribe from Unity input

interactionInput.Unbind()

Manually fire all callbacks

interactionInput.Invoke()

Properties

Name

The display name and lookup key for this input. Set during construction.

InputPhase

The Unity input phase this input subscribes to. Configured via Inspector.

Constructor

Parameter
Type
Description

name

string

The display name and dictionary key for this input

Creates a new InteractionInput with an empty callback list. The inputActionReference and inputPhase are serialized fields configured in the Inspector.

Methods

AddCallback

Registers a callback to be invoked when this input fires.

Parameter
Type
Description

callback

Action

The callback to add

RemoveCallback

Unregisters a previously added callback.

Parameter
Type
Description

callback

Action

The callback to remove

ClearCallbacks

Removes all registered callbacks.

Bind

Subscribes the internal handler to the Unity InputAction event matching the configured inputPhase:

Phase
Subscribes to

STARTED

inputActionReference.action.started

PERFORMED

inputActionReference.action.performed

CANCELED

inputActionReference.action.canceled

Unbind

Unsubscribes the internal handler from the Unity InputAction event matching the configured inputPhase.

Invoke

Manually fires all registered callbacks in reverse order. This is also called internally when the Unity input event fires.

circle-info

Callbacks are invoked in reverse iteration order (Count - 1 down to 0). This allows callbacks to safely remove themselves during invocation without causing index-out-of-range errors.

Serialized Fields

Field
Type
Description

inputActionReference

InputActionReference

Unity Input System action reference (configured in Inspector)

name

string

Display name / lookup key

inputPhase

InteractionInputPhase

Which input phase to bind to

inputCallbacks

List<Action>

Registered callbacks (Odin serialized, populated at runtime)

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated