Decorator
Basic info about decorators in AI Tree
Last updated
Basic info about decorators in AI Tree
Last updated
Decorators are special nodes that allow you to add conditions or constraints to other nodes (such as tasks or sequences) within the behavior tree. Decorators check the state or conditions before the node they are attached to is executed. If the condition is not met, the execution of the tree may be halted, ignored, or altered depending on the logic defined in the decorator.
Execution Conditions: Decorators can check various conditions, such as character health, distance to a target, item availability, etc. If the condition is not met, the execution of child nodes will be stopped.
State Checking: They can be used to check the state of an object or NPC. For example, if an NPC is in an attacking state, the decorator may prevent the execution of other tasks.
Caching Results: Some decorators can cache the result of checks to avoid unnecessary performance overhead if the same condition is checked multiple times.
Changing Execution Flow: Decorators can modify the behavior of the tree. For example, if a decorator is active, child nodes may be executed differently (e.g., they may be executed in a different order).
Blackboard-based Decorator: This decorator checks values in the blackboard. For instance, it might check whether the value of the "Target" variable is valid (i.e., not null), and if it is not, the execution of child nodes will be halted.
Cooldown Decorator: This decorator can limit the execution of a task if a certain cooldown period has not yet elapsed. For example, if an NPC uses an ability, the decorator may prevent the ability from being reused until the cooldown period is over.
IsAtLocation Decorator: Checks whether the target is within a certain range. If the target is too far away, the execution of child nodes will be stopped.
The possibilities of decorators are not limited to the built-in types, you can easily create your own decorators for special cases.