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 InteractionInputRemarks
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
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
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.
callback
Action
The callback to add
RemoveCallback
Unregisters a previously added callback.
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:
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.
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
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
Must assign InputActionReference in Inspector
If inputActionReference is null when Bind() is called, a NullReferenceException occurs. Always assign the reference in the Inspector.
Bind/Unbind must be paired
Calling Bind() without a matching Unbind() leaves orphaned subscriptions on the Unity InputAction, which can cause callbacks to fire after the interaction has ended.
Callbacks are cleared on deserialization
InteractionInputTable.OnAfterDeserialize() calls UpdateInteractionInputs(), which calls ClearCallbacks() on each input before re-registering. Any manually added callbacks are lost on deserialization.
See Also
InteractionInputTable — manages a collection of
InteractionInputentriesInteractionInputPhase — the phase enum
InteractionInputAttribute — attribute that drives callback discovery
Last updated