Behavioural Trees in ERGS
Behavioural Trees (BT) are a powerful alternative to standard state-based logic for managing complex automated behaviours, NPC-like interactions, and sophisticated room environmental systems. While standard logic in ERGS is often event-driven, Behavioural Trees are status-driven, constantly evaluating the environment to decide the best course of action.
Core Concepts: Success, Failure, and Running
Every node in a Behavioural Tree returns one of three statuses to its parent:
- Success: The task was completed successfully or the condition was met.
- Failure: The task could not be completed or the condition was not met.
- Running: The task is still in progress (e.g., a "Wait" timer or a moving motor).
The "Logic" (Tri-state) System
To handle advanced escape room scenarios, ERGS introduces the Logic (Status) type, which extends standard Boolean logic with a neutral state: * 1 (Success): Task finished / Active. * 0 (Failure): Task in progress / Error / Failed. * -1 (Neutral): Idle / Not started / Task disabled.
Key Node Types
1. The Entry Point
- Root: The mandatory starting point. It serves as the single entry point for evaluation. In ERGS, the Root can have a
TickInterval(e.g., every 5–10 seconds) to manage "Director" logic without overloading the CPU.
2. Composite Nodes (Decision Makers)
- Selector: The "Priority" node. It evaluates children from left to right and stops at the first one that succeeds. Use this for fallback logic (e.g., "If emergency, do X; otherwise, do Y").
- Sequence: The "Checklist" node. It evaluates children in order and stops if any of them fail. Use this for linear multi-part tasks.
3. Decorators (Conditions & Filters)
Decorators are attached to nodes to control their execution flow based on specific conditions.
- GameState Decorator: Specifically designed for escape rooms. it monitors the status of game checkpoints:
- Is Finished?: Checks if the task is already completed.
- Is In Progress?: Checks if the players are currently working on it.
- Is Late?: Checks if the players have exceeded the Recommended or Late Time defined in the GameState.
- Blackboard (Global Var) Decorator: Compares values in global variables, such as hint counts or player frustration levels.
- Inverter: Flips the result (Success becomes Failure and vice versa).
4. Leaf Nodes (The Doers)
- Action: Triggers a standard ERGS action (e.g., relay, sound, LLM hint) and returns Success or Failure.
- Wait: Pauses the branch, returning "Running" until the timer expires.
Use Case: The "Game Director"
Behavioural Trees in ERGS act as an automated Game Director, dynamically adapting the experience:
- Adaptive Difficulty: If a GameState Decorator returns
Is Late, the tree can trigger anActionto simplify the puzzle or provide a hint. - Smart Hinting: The tree can check if a puzzle is
In Progressfor too long before allowing the LLM NPC to speak. - Auto-Progression: If players are critically behind, the BT can trigger an
AutoSolveaction to open a door and keep the game moving. - Atmospheric Triggering: If the tree detects an
Idlestate (no progress for a long time), it can trigger ambient sounds or lighting effects to re-engage players.
Best Practices
- Left-to-Right Priority: Always place your most critical or "emergency" logic on the leftmost branches of a Selector.
- Throttle the Root: Use a slower tick rate (e.g., 5s) for high-level "Director" logic to save resources.
- Visual Debugging: Use the ERGS editor to monitor connection colors—Green for Success, Red for Failure, and animated pulses for Running.