Skip to content

Event System

The Interaction System uses two complementary event layers:

  • C# events (event Action<TArgs>) — for code-side subscriptions with full type safety and zero Inspector setup.
  • UnityEvents (SerializedField) — for Inspector-wired callbacks, usable by designers without code.

Both layers fire for the same lifecycle points.


IInteractor C# events

All events are defined on IInteractor and implemented in InteractorBase.

InteractionStarted

Fires when the player first focuses on an interactable target.

interactor.InteractionStarted += (InteractionLifecycleEventArgs args) =>
{
// args.Target — the IInteractable that was focused
// args.Context — the current InteractionContext
highlightOutline.Enable(args.Target.GetGameObject());
};

ActionsDiscovered

Fires after focus is established and the action list has been built. Carries the full (visible) action list.

interactor.ActionsDiscovered += (ActionsDiscoveredEventArgs args) =>
{
// args.Target — the focused IInteractable
// args.Actions — List<IInteractableAction> of visible actions
// args.Context — the current InteractionContext
hud.ShowActionMenu(args.Actions);
};

ShowActionsDiscovered

Fires specifically when the player enters “show actions” mode (by calling ShowInteractions()). Use this to display the selection UI; ActionsDiscovered fires earlier and is better for background setup.

ActionSelectionChanged

Fires whenever the selected action index changes (cycling with SelectNextAction / SelectPreviousAction).

interactor.ActionSelectionChanged += (ActionSelectionChangedEventArgs args) =>
{
// args.Target — the focused IInteractable
// args.Action — the newly selected IInteractableAction
// args.Index — its index in the visible actions list
hud.HighlightAction(args.Index);
};

ActionExecuted

Fires after an action has been executed successfully.

interactor.ActionExecuted += (ActionExecutedEventArgs args) =>
{
// args.Target — the IInteractable
// args.Action — the IInteractableAction that ran
// args.Result — InteractionResult (Success, Failed, NotAvailable)
audioSource.PlayOneShot(executeClip);
};

InteractionEnded

Fires when focus is lost (player looks away, EndInteraction() is called, or the target is destroyed).

interactor.InteractionEnded += (InteractionLifecycleEventArgs args) =>
{
hud.HideActionMenu();
highlightOutline.Disable();
};

IInteractor UnityEvents

The same lifecycle points are exposed as serializable UnityEvent fields in the Inspector on InteractorBase:

Inspector fieldEquivalent C# event
onInteractionStartedInteractionStarted
onActionsDiscoveredActionsDiscovered
onShowActionsDiscoveredShowActionsDiscovered
onActionSelectionChangedActionSelectionChanged
onActionExecutedActionExecuted
onInteractionEndedInteractionEnded

Drag any component method to these fields in the Inspector without writing any code.


IInteractableAction.OnExecuted

Every action type (InteractableAction, InteractableActionSO, and wrappers) has a single OnExecuted UnityEvent that fires immediately after Execute() completes.

Use it for per-action feedback that doesn’t need to go through the main interactor pipeline (e.g., a particle burst tied to a specific pickup, audio on a door open).


Event args reference

InteractionLifecycleEventArgs

PropertyTypeDescription
TargetIInteractableThe focused interactable
ContextInteractionContextCurrent interaction context

ActionsDiscoveredEventArgs

PropertyTypeDescription
TargetIInteractableThe focused interactable
ActionsList<IInteractableAction>Visible (filtered) actions
ContextInteractionContextCurrent interaction context

ActionSelectionChangedEventArgs

PropertyTypeDescription
TargetIInteractableThe focused interactable
ActionIInteractableActionNewly selected action
IndexintIndex in the visible actions list

ActionExecutedEventArgs

PropertyTypeDescription
TargetIInteractableThe focused interactable
ActionIInteractableActionAction that was executed
ResultInteractionResultOutcome of execution

InteractionContext

PropertyTypeDescription
InteractorIInteractorThe interactor that initiated the interaction