InteractionInputTable
Reflection-based collection that auto-discovers methods marked with [InteractionInput] on an Interaction subclass, creates InteractionInput entries for each unique input name, and manages binding/unbinding all inputs as a group. Implements IEnumerable<InteractionInput> for iteration and ISerializationCallbackReceiver to refresh bindings on deserialization.
Definition
Namespace: Paragon.Townskeep.InteractionSystem
Assembly: Townskeep.dll
[Serializable, HideReferenceObjectPicker]
public class InteractionInputTable : IEnumerable<InteractionInput>, ISerializationCallbackReceiverImplements: IEnumerable<InteractionInput>, ISerializationCallbackReceiver
Remarks
InteractionInputTable is the bridge between declarative [InteractionInput] attributes and runtime input handling. It performs two key operations:
Discovery — On construction and after deserialization, it scans the owning
Interactionsubclass via reflection for methods bearing[InteractionInputAttribute]. Each discovered method is converted to anActiondelegate and registered on the correspondingInteractionInput.Lifecycle Management —
Bind()andUnbind()iterate all entries and subscribe/unsubscribe them from Unity's Input System in bulk. This is called automatically byInteraction.OnBegin()andInteraction.OnComplete()/OnCancel().
The table stores inputs in a Dictionary<string, InteractionInput> keyed by the input name. Multiple methods can share the same input name — they are all registered as callbacks on the same InteractionInput entry.
Name Resolution
When [InteractionInput] has an explicit Name, that name is used as the dictionary key. When Name is empty, the method name is split from PascalCase via Odin's SplitPascalCase() extension (e.g., OnChopTree → "On Chop Tree").
Quick Lookup
Add a runtime callback
inputTable.AddInputCallback("InputName", callback)
Remove a runtime callback
inputTable.RemoveInputCallback("InputName", callback)
Check if input exists
inputTable.TryGetInputCallback("InputName", out input)
Subscribe all to Unity
inputTable.Bind()
Unsubscribe all from Unity
inputTable.Unbind()
Get input count
inputTable.Count
Properties
Count
The number of registered InteractionInput entries.
Constructor
interaction
Interaction
The owning interaction to scan for [InteractionInput] methods
Creates the table, stores the interaction reference, and immediately calls UpdateInteractionInputs() to discover and register all attributed methods.
Methods
AddInputCallback
Adds a callback to an existing named input at runtime.
inputName
string
The name of the input (must match a discovered entry)
callback
Action
The callback to add
Logs Debug.LogError if inputName is not found in the table. Ensure the name exactly matches.
RemoveInputCallback
Removes a callback from an existing named input.
inputName
string
The name of the input
callback
Action
The callback to remove
Logs Debug.LogError if inputName is not found in the table.
TryGetInputCallback
Attempts to retrieve an InteractionInput by name.
inputName
string
The name to look up
interactionInput
out InteractionInput
The found input, or null
Returns: true if the input was found.
Bind
Subscribes all InteractionInput entries to their respective Unity InputAction phase events. Called automatically by Interaction.OnBegin() when the interactor has input control.
Unbind
Unsubscribes all InteractionInput entries from their respective Unity InputAction phase events. Called automatically by Interaction.OnComplete() and Interaction.OnCancel().
GetEnumerator
Iterates over all InteractionInput values in the table.
Internal Mechanism
UpdateInteractionInputs
Called on construction and OnAfterDeserialize(). Performs the full discovery and registration pipeline:
UpdateInteractionInputs() preserves serialized InteractionInput instances (including their InputActionReference and InputPhase settings) when possible. If an input name already exists in the table, the existing instance is reused — only its callbacks are refreshed.
Common Pitfalls
Callbacks cleared on deserialization
OnAfterDeserialize() triggers UpdateInteractionInputs(), which calls ClearCallbacks() on each input before re-registering attribute-discovered methods. Any callbacks added manually via AddInputCallback() before deserialization are lost.
Input names are case-sensitive
Dictionary lookup uses exact string matching. "Chop" and "chop" are different inputs.
Attributed methods must be Action-compatible
Methods are converted via MethodInfo.CreateDelegate(interaction) to System.Action. They must have no parameters and return void. Methods with parameters will throw an ArgumentException during delegate creation.
Examples
Accessing the table from an Interaction
Querying inputs
See Also
InteractionInput — individual input entries managed by this table
InteractionInputAttribute — attribute driving reflection discovery
InteractionInputPhase — phase enum
Last updated