InputActionCallback
Delegate wrapper that adapts arbitrary callback signatures into Unity's Action<InputAction.CallbackContext> format. Automatically handles type conversion — methods with no parameters, typed value parameters (Action<Vector2>, Action<float>, etc.), or the full CallbackContext are all supported transparently.
Definition
Namespace: Paragon.Core.InputSystem
Assembly: Paragon.dll
public class InputActionCallbackRemarks
Unity's Input System requires all callbacks to accept InputAction.CallbackContext. InputActionCallback eliminates this boilerplate by wrapping delegates with different signatures:
Action (no params)
_ => callback() — context is discarded
Action<InputAction.CallbackContext>
Used directly — no wrapping
Action<T> where T : struct
ctx => callback(ctx.ReadValue<T>()) — value auto-extracted
The generic wrapping uses cached reflection: CallbackWrapper<T> is a generic method resolved once per T and cached in a static dictionary. This avoids repeated reflection overhead for the same input type.
The class also provides an implicit conversion operator to Action<InputAction.CallbackContext>, allowing it to be used directly with Unity's InputAction.started, performed, and canceled events.
Quick Lookup
Create from a delegate
InputActionCallback.From(myDelegate)
Use as Unity callback
Implicit conversion: inputAction.performed += myCallback
Methods
From (static factory)
Creates an InputActionCallback from any supported delegate type.
callbackDelegate
Delegate
The callback to wrap. Supported: Action, Action<CallbackContext>, Action<T> where T : struct
Returns: A new InputActionCallback wrapping the delegate.
The factory uses pattern matching to select the wrapping strategy:
Action→ wraps with context discardAction<InputAction.CallbackContext>→ passes throughAny other single-parameter delegate → routes through
WrapCallback()for generic type conversion
Operators
Implicit to Action<CallbackContext>
Allows InputActionCallback to be used wherever Unity expects Action<InputAction.CallbackContext>.
This enables direct use with Unity's event system:
Internal Mechanism
Type Conversion Pipeline
CallbackWrapper<TInput>
Internal generic method that creates the actual wrapping lambda:
This is never called directly — it is invoked via reflection with the appropriate TInput type.
The wrapper method cache (wrapperMethods dictionary) is static and shared across all InputActionCallback instances. Each unique input type (Vector2, float, etc.) is resolved and cached once for the application lifetime.
Common Pitfalls
Only struct value types supported for auto-extraction
The CallbackWrapper<TInput> has a where TInput : struct constraint. Reference types cannot be auto-extracted from CallbackContext.ReadValue<T>(). Use Action<InputAction.CallbackContext> and manually read the value for reference types.
Single-parameter delegates only
WrapCallback() reads callback.Method.GetParameters()[0] — it assumes exactly one parameter. Multi-parameter delegates will cause an index-out-of-range exception.
Private constructor
InputActionCallback cannot be instantiated directly. Always use InputActionCallback.From(delegate).
See Also
InputActionMapBinding — uses
From()to wrap discovered callback methodsInputActionCallbackAttribute — attribute that marks methods for discovery
InputActionPhase — phase enum used in callback binding
Last updated