Composite
Last updated
Last updated
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.
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.
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.
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.
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.
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.