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 : ParagonObject

Inheritance: 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 type T and 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

Goal
How

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.

Parameter
Type
Description

gameObject

GameObject

The owning GameObject

circle-exclamation

TryInteractWith<TInteraction>

Attempts to start an interaction of a specific type with the given interactable.

Parameter
Type
Description

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.

circle-exclamation

TryInteractWith (trigger-based)

Attempts to start an interaction matched by the given trigger.

Parameter
Type
Description

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.

circle-info

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.

Parameter
Type
Description

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

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Composing Interactor into a Character

Listening for Interaction Events

See Also

Last updated