Possessable

MonoBehaviour component placed on entities that can be possessed (characters, NPCs, vehicles). Manages the possession state — tracks the current Possessor, reparents transforms for spatial coupling, executes configurable PossessAction hooks, and fires events on possession/release.

Definition

Namespace: Paragon.Townskeep.PossessionSystem Assembly: Townskeep.dll

public class Possessable : ParagonBehaviour

Inheritance: SerializedMonoBehaviourParagonBehaviourPossessable

Remarks

Possessable is one half of the possession pattern. An entity that can be possessed has a Possessable component; an entity that can possess has a Possessor component. The flow is initiated by the Possessor calling Possess(possessable).

Possession lifecycle

When OnPossessed(possessor) is called:

  1. Stores the possessor reference

  2. Moves the possessor's GameObject to the possessable's scene

  3. Snaps the possessor's position to the possessable's position

  4. Parents the possessable's transform under the possessor's transform

  5. Executes the possessedAction (if assigned)

  6. Fires the Possessed event

When OnReleased(possessor) is called:

  1. Clears the possessor reference to null

  2. Unparents the possessable's transform (sets parent to null)

  3. Executes the releasedAction (if assigned)

  4. Fires the Released event

Spatial coupling

While possessed, LateUpdate synchronizes the possessor's position to the possessable's position and resets the possessable's local position to zero. This keeps the possessor physically attached to the possessed entity (e.g., the Player follows the Character).

IPossessable interface

The sibling IPossessable component (e.g., Character) provides the higher-level identity. Possessable.Owner returns the IPossessable, enabling typed queries like possessable.IsPossessedBy<Player>() which checks the possessor's IPossessor owner type.

Quick Lookup

Goal
How

Check if possessed

possessable.IsPossessed()

Check possessor type

possessable.IsPossessedBy<Player>()

Get the possessor

possessable.GetPossessor()

Get typed possessor

possessable.TryGetPossessor<Player>(out var player)

Properties

Owner (internal)

The IPossessable component on the same GameObject. Used internally by the extension methods for typed queries.

Fields

possessedAction

Optional PossessAction executed when this entity is possessed. Configured in the Inspector.

releasedAction

Optional PossessAction executed when this entity is released. Configured in the Inspector.

Events

Possessed

Fires when this entity is possessed.

Released

Fires when this entity is released from possession.

Methods

Awake

Caches the IPossessable component from the same GameObject.

IsPossessed

Returns true if this entity is currently possessed.

IsPossessedBy<TPossessor>

Returns true if the possessor's IPossessor.Owner is of type TPossessor.

GetPossessor

Returns the current Possessor, or null if not possessed.

TryGetPossessor<TPossessor>

Attempts to get the possessor's IPossessor.Owner as a specific type.

OnPossessed

Called by Possessor.Possess(). Sets up spatial coupling, executes the possessedAction, and fires the Possessed event.

Parameter
Type
Description

possessor

Possessor

The possessor taking control

OnReleased

Called by Possessor.Release(). Clears the possessor, unparents, executes the releasedAction, and fires the Released event.

Parameter
Type
Description

possessor

Possessor

The possessor releasing control

LateUpdate

Synchronizes the possessor's position to match the possessable's position while possessed. Resets the possessable's local position to zero.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

See Also

  • Possessor — the other half of the possession pattern (the possessing side)

  • Player — a concrete IPossessor implementation

Last updated