Interactor
Serializable object representing an entity that can initiate interactions with Interactable targets. Manages active interactions, provides typed lookup for running interactions, and fires events on interaction begin/end.
Definition
Namespace: Paragon.Townskeep.InteractionSystem Assembly: Townskeep.dll
[Serializable]
public class Interactor : ParagonObjectInheritance: ParagonObject → Interactor
Remarks
Interactor is not a MonoBehaviour. It is a [Serializable] class intended to be composed into MonoBehaviours or other systems (e.g., a character controller, NPC brain). It is initialized with a GameObject reference and tracks all currently active interactions.
Two overloads of TryInteractWith support different use cases:
By type (
TryInteractWith<T>) — finds the first available interaction of typeTand executes it.By trigger (
TryInteractWith(interactable, trigger, out interaction)) — finds the first interaction whose trigger matches and executes it.
HasInputControl() checks whether the interactor's GameObject has an IPossessor component that is a Player, used by Interaction to determine whether to bind input actions.
Quick Lookup
Initialize
interactor.Initialize(gameObject)
Start interaction by type
interactor.TryInteractWith<SitInteraction>(interactable, out var sit)
Start interaction by trigger
interactor.TryInteractWith(interactable, trigger, out var interaction)
Check for active interaction
interactor.TryGetActiveInteractionOfType<T>(out var interaction)
End interaction with target
interactor.EndInteractionWith(interactable)
Listen for interaction events
interactor.InteractionBegin += OnBegin
Properties
gameObject
The GameObject this interactor is associated with. Set during Initialize().
Events
InteractionBegin
Fired when an interaction begins on this interactor.
InteractionEnd
Fired when an interaction ends on this interactor.
Methods
Initialize
Initializes the interactor with its owning GameObject. Must be called before any interaction attempts.
gameObject
GameObject
The owning GameObject
Calls base.Initialize() internally. Must be called exactly once before use.
TryInteractWith<TInteraction>
Attempts to start an interaction of a specific type with the given interactable.
interactable
Interactable
The target to interact with
interaction
out TInteraction
The started interaction, or null
Returns: true if a matching interaction was found and started.
Assertion: Asserts that the matched InteractionContext is not already running. Will fire Debug.Assert if attempting to start a context that is mid-execution.
TryInteractWith (trigger-based)
Attempts to start an interaction matched by the given trigger.
interactable
Interactable
The target to interact with
trigger
InteractionTrigger
The trigger to match against
interaction
out Interaction
The started interaction, or null
Returns: true if a matching interaction was found and started.
This overload first checks CanInteractWith() (enabled, not busy, has available interactions) before searching for a trigger match.
TryGetActiveInteractionOfType<TInteraction>
Finds an active interaction of the specified type.
Returns: true if an active interaction of the given type was found.
TryGetActiveInteractionOfType (non-generic)
Finds an active interaction by System.Type.
TryGetActiveInteractionWith<TInteraction>
Finds an active interaction with a specific interactable.
Returns: true if an active interaction with the given interactable was found.
GetActiveInteractions
Returns all currently active interactions.
EndInteractionWith
Cancels the active interaction with the specified interactable.
interactable
Interactable
The target whose interaction to cancel
HasInputControl
Returns true if the interactor's GameObject has a Player possessor, meaning input should be bound during interactions.
OnInteractionBegin
Called by Interaction.OnBegin() to register an active interaction and fire the InteractionBegin event.
OnInteractionEnd
Called by Interaction.OnComplete() or Interaction.OnCancel() to deregister an active interaction and fire the InteractionEnd event.
OnDebug
Calls OnDebug() on all active interactions for debug visualization.
Common Pitfalls
Uninitialized interactor Calling TryInteractWith before Initialize(gameObject) will result in null references. Always initialize first.
Multiple interactions with same interactable Interactable.IsBusy prevents multiple simultaneous interactions on the same target. However, an Interactor can have multiple active interactions with different interactables.
HasInputControl depends on IPossessor HasInputControl() checks GetComponent<IPossessor>() is Player. If the possession system is not set up, this will always return false and input will never bind.
Examples
Composing Interactor into a Character
Listening for Interaction Events
See Also
Interactable — target of interactions
Interaction — abstract interaction logic
InteractionTrigger — trigger matching for trigger-based interactions
Last updated