상세 컨텐츠

본문 제목

Behavior Tree (1. Composite nodes

Unreal Engine

by geminanolja 2025. 1. 13. 03:15

본문

Composite nodes

 -> defines the basic rules for how the branch can be executed (e.g. Sequence ,  Selector )

  • Sequence : Executing All children from L to R (Stop executing when one of them fails)
  • Selector : Executing till one of the children nodes from L to R

How to Handle 

If you want the AI to continue finding enemies and moving to them even if attacking fails, you can use a Selector node combined with the Sequence.

Example:

Root
 ├── Selector
 │    ├── Sequence
 │    │    ├── Find Enemy
 │    │    ├── Move to Enemy
 │    │    └── Attack Enemy
 │    └── Retry (Fallback Node)

Here’s what happens:

  1. The Selector runs the Sequence:
    • If Attack Enemy fails, the Selector returns to the fallback logic (e.g., Retry or Idle).
  2. Fallback logic re-triggers the Sequence (if designed this way).
    • The Sequence starts again with "Find Enemy" and continues the cycle.

Behavior Tree Flow

 

  • The character would have moved toward the enemy (thanks to the successful execution of "Move to Enemy").
  • The failure occurs only during "Attack Enemy".
  • First Execution
    1. Selector node:
      • Executes the Sequence node first.
    2. Sequence node:
      • Find Enemy succeeds → moves to the next task.
      • Move to Enemy succeeds → moves to the next task.
      • Attack Enemy fails → the entire Sequence fails, and control returns to the Selector.
    Selector's Fallback Behavior
  • 1) After the Sequence fails:
    • The Selector tries the next child node (the "Retry" or "Fallback" node in your example).
    • This could trigger re-execution of the Sequence or a new behavior (e.g., retreat, idle, or search again)

 

            2) if the sequence node succeeds,

    1. The Selector node checks its child nodes from left to right
 
    2. If the Sequence node succeeds:
  • The Selector stops execution since one of its children has succeeded.
  • The Retry (Fallback Node) will not execute, because the Selector only moves to the next child when the current one fails.

 


Key Differences Between Sequence and Selector

AspectSequenceSelector
Execution Order Executes all children sequentially Tries children sequentially, stops on success
Success All children must succeed Stops as soon as one child succeeds
Failure Stops as soon as one child fails Fails only if all children fail
Use Case For tasks that must happen in sequence For fallback or alternative strategies

 

 

관련글 더보기