InteractionCondition

Abstract base class for defining boolean conditions that gate interaction availability. Subclass and implement OnEvaluate() to define custom logic. Supports an Inspector-configurable negate flag to invert the result without creating a separate condition class.

Definition

Namespace: Paragon.Townskeep.InteractionSystem Assembly: Townskeep.dll

[Serializable]
public abstract class InteractionCondition

Remarks

InteractionCondition follows the Template Method pattern: the public Evaluate() method handles negation logic, then delegates to the abstract OnEvaluate() for subclass-specific evaluation.

Conditions are owned by an InteractionContext, which evaluates all of them via conditions.All(c => c.Evaluate(...)) before an interaction can execute. This means:

  • All conditions must return true for the interaction to be available (logical AND)

  • A single false result blocks the interaction

The context field provides access to the owning InteractionContext after Initialize() is called, allowing conditions to reference the interaction, interactor, or interactable through the context if needed.

Quick Lookup

Goal
How

Create a custom condition

Subclass and override OnEvaluate()

Invert condition logic

Toggle negate in Inspector

Access interaction context

Use this.context (available after Initialize())

Fields

context (protected)

The owning InteractionContext. Set by Initialize(). Provides access to Interactor, Interactable, and the Interaction itself.

negate (serialized)

When true, the result of OnEvaluate() is inverted. Configured in the Inspector.

Methods

Initialize

Called by InteractionContext.Initialize() during setup. Stores the context reference for use in OnEvaluate().

Parameter
Type
Description

context

InteractionContext

The owning interaction context

Evaluate

Evaluates the condition for a given interactable/interactor pair. Applies negation if configured.

Parameter
Type
Description

interactable

Interactable

The object being interacted with

interactor

Interactor

The entity attempting to interact

Returns: The condition result (potentially negated).

Logic:

Extension Points

Required Overrides

Method
Purpose

OnEvaluate(Interactable, Interactor)

Core condition logic — return true if the interaction should be available

OnEvaluate (abstract)

Implement this method to define the condition's logic.

Parameter
Type
Description

interactable

Interactable

The object being interacted with

interactor

Interactor

The entity attempting to interact

Returns: true if the condition is met (before negation is applied).

Implementation Requirements

When subclassing, you MUST:

  1. Override OnEvaluate() and return a boolean result

  2. Mark the class [Serializable] for Unity serialization

You SHOULD:

  • Keep OnEvaluate() fast and side-effect-free (it may be called frequently during interaction checks)

  • Use context for accessing shared interaction state rather than caching references

  • Use [SerializeField] for Inspector-configurable parameters

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Distance-based condition

State-based condition

Using the negate flag

In the Inspector, you can toggle negate to invert any condition:

Condition
Negate
Effective Meaning

WithinRangeCondition

false

"Must be within range"

WithinRangeCondition

true

"Must be outside range"

HasItemCondition

false

"Must have item"

HasItemCondition

true

"Must NOT have item"

See Also

Last updated