Skip to main content

Advanced Logic Patterns

Moving beyond simple connections, this chapter dives into the Runtime Architecture of the Flow System.

Understanding how the system executes Triggers versus Chains, and how Node configurations interact with Event configurations, is the key to mastering complex game logic.


βš™οΈ Core Mechanics: Trigger vs. Chain​

In the Flow Graph, a connection isn't just a line; it's a Transfer of Control. The type of the Target Node determines how that control is handled.

Feature🟠 Trigger Node🟒 Chain Node
Execution ModeParallel (Fan-Out)Serial (Sequence)
Blocking?❌ Non-Blockingβœ… Blocking
Technical Impl.Fire-and-ForgetCoroutine Yield
Data FlowPasses data to all children instantly.Passes data to the next child only after finishing.

1. The Trigger Mechanism (Parallel)​

When the flow enters a Trigger Node:

  1. The system calculates the Priority of all connected Triggers.
  2. It executes them one by one in a loop.
  3. Crucially, it does not wait for a Trigger to finish its tasks before starting the next one.
  4. Result: To the player, all effects (Sound, UI, Particles) appear to happen simultaneously in the same frame.

2. The Chain Mechanism (Sequential)​

The Chain Node has a complex lifecycle designed for pacing. It holds the flow using Two Layers of Delay:

  1. Pre-Execution: Waits for Start Delay.
  2. Execution: Raises the event.
  3. Post-Execution: Waits for Duration OR Wait For Completion.
  4. Signal: Only then does it fire the Next Node.

⏱️ The Timeline of Execution​

It is vital to understand how Node Configuration (Graph) interacts with Event Configuration (Inspector).

The "Double Delay" Rule​

If you configure a delay on the Node AND a delay on the Event, they are Additive.

Total Time to Action = Node Start Delay + Event Action Delay

Visual Timeline​

Here is the millisecond-by-millisecond breakdown of a single Chain Node execution:

[Flow Enters Node]
β”‚
β”œβ”€β”€ 1. Node Condition Check (Graph Layer)
β”‚ πŸ›‘ If False: STOP.
β”‚
β”œβ”€β”€ 2. Node Start Delay (Graph Layer) ⏱️
β”‚ ⏳ Waiting...
β”‚
β”œβ”€β”€ 3. Event Raised (Core Layer) πŸš€
β”‚ β”‚
β”‚ β”œβ”€β”€ a. Event Condition Check (Inspector Layer)
β”‚ β”‚ πŸ›‘ If False: Skip Actions (But flow continues!)
β”‚ β”‚
β”‚ β”œβ”€β”€ b. Event Action Delay (Inspector Layer) ⏱️
β”‚ β”‚ ⏳ Waiting...
β”‚ β”‚
β”‚ └── c. UnityActions Invoke (Game Logic) 🎬
β”‚ (e.g., Play Animation, Subtract Health)
β”‚
β”œβ”€β”€ 4. Node Duration / Wait (Graph Layer) ⏳
β”‚ πŸ›‘ Flow is BLOCKED here.
β”‚ (Waits for Duration seconds OR Async Completion)
β”‚
└── 5. Signal Next Node ⏭️
Architecture Nuance
  • Event Conditions only stop the local side effects (Action c). They DO NOT stop the Flow Graph from proceeding to step 4 and 5.
  • To stop the Flow Graph logic, you must use Node Conditions (Step 1).

πŸ› οΈ Cookbook: Real-World Design Patterns​

Here are the standard architectural patterns for solving common game development problems.

1. The "Cinematic" Pattern (Cutscene)​

Goal: A strictly timed sequence of events. Scenario: Camera moves -> Door opens -> Character walks in -> Dialog starts.

alt text

  • Structure: Root βž” Chain βž” Chain βž” Chain.
  • Configuration:
    • Use Chain Nodes (🟒) for every step.
    • Use Node Duration (⏳) to pace the sequence.
      • Example: If "Door Open Anim" takes 2.0s, set the Node Duration to 2.0 to ensure the character doesn't walk through a closed door.

2. The "Broadcaster" Pattern (Player Death)​

Goal: One state change triggering multiple independent systems. Scenario: Player dies. You need to: Play Sound, Show Game Over UI, Spawn Ragdoll, Save Game.

alt text

  • Structure: Root βž” Multiple Triggers.
  • Configuration:
    • Root: OnPlayerDeath.
    • Children: 4 separate Trigger Nodes (🟠).
    • Why: If the "Save Game" system hangs or errors out, you don't want it to block the "Game Over UI" from appearing. Parallel execution ensures safety.

3. The "Hybrid Boss" Pattern (Complex State)​

Goal: Complex AI phase transition. Scenario: Boss enters Phase 2. He roars (animation), AND SIMULTANEOUSLY the music changes and the arena turns red. WHEN the roar finishes, he starts attacking.

alt text

  • Structure:
    1. Root (OnHealthThreshold).
    2. Chain Node (BossRoarAnim) with Wait For Completion checked (or Duration set to anim length).
    3. Trigger Node (MusicChange) attached to the Root (Parallel to Roar).
    4. Trigger Node (ArenaColorChange) attached to the Root (Parallel to Roar).
    5. Chain Node (StartAttack) attached to the BossRoarAnim node.
  • Flow:
    • Music and Color happen immediately alongside the Roar.
    • The StartAttack waits until the Roar Chain Node is fully finished (Step 4 in Timeline).

🎯 Summary: When to use what?​

RequirementUse Node TypeWhy?
"Do X, then do Y"Chain (🟒)Guarantees order via blocking.
"Do X, Y, and Z all at once"Trigger (🟠)Fire-and-forget. Parallel execution.
"If HP < 0, do X"Node ConditionStops the flow logic entirely.
"Only play sound if not muted"Event ConditionStops the side effect, keeps flow logic running.
"Wait before doing X"Node Start DelayDelays the event raise.
"Wait after X before doing Y"Node Duration(Chain Only) Delays the next node signal.