Composite

In the context of AI Tree, composite nodes are nodes that serve to organize other nodes and manage their execution. Composite nodes allow you to create more complex behavior structures by grouping child nodes into logical sets and defining the order in which they are executed.

Key Aspects of Composite Nodes:

  1. Node Organization:

    • Composite nodes can contain other nodes, such as tasks, decorators, and services. These child nodes are grouped under a single composite node, which controls their execution.

  2. Defining Execution Logic:

    • Composite nodes determine how and in what order their child nodes are executed. This could be sequential execution, selecting the first successful node, or parallel execution of multiple nodes simultaneously.

  3. Types of Composite Nodes:

    • There are several types of composite nodes in Behavior Trees:

      • Sequence: Executes child nodes in order until one of them fails. If all child nodes succeed, the sequence returns success.

      • Selector: Checks child nodes in order and returns success if one of them succeeds. If all child nodes fail, it returns failure.

      • Parallel: Allows multiple child nodes to run simultaneously. The success or failure of the parallel node depends on its settings — you can set it to complete once all nodes succeed or once any one of them does.

  4. Controlling Behavior Flow:

    • Composite nodes help manage the flow of execution in the behavior tree, allowing the developer to organize when and under what conditions certain NPC actions are performed.

Example of Usage:

Imagine an NPC that needs to first check its surroundings, then move to a target, and finally attack. For this, you can use a Sequence composite node, which will execute the child tasks in order — checking the environment, moving to the target, and attacking. If the NPC fails to perform one of these tasks (for example, if the target is not found), the sequence will end in failure, allowing the NPC to switch to another behavior branch.

Composite nodes are a key part of building complex hierarchies in Behavior Trees as they manage the structure and logic of NPC actions, making the behavior flexible and adaptable to changing game conditions.

SequencerSelectorParallel

Last updated