---
description: Basic info about decorators in AI Tree
---

# Decorator

[**Decorators** ](../../nodes/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.

<figure><img src="https://2203000093-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGOxTM7Aj9oiVaIINrEkE%2Fuploads%2FVMe56m0NqKFq5zmrd1Gg%2Fimage.png?alt=media&#x26;token=beb9724c-a3f7-43b6-8615-8163d4d9da5a" alt="" width="375"><figcaption><p>Decorator image (blue box)</p></figcaption></figure>

#### Main Functions of Decorators:

1. **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.
2. **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.
3. **Caching Results**: Some decorators can cache the result of checks to avoid unnecessary performance overhead if the same condition is checked multiple times.
4. **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).

#### Examples of Decorators:

1. **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.
2. **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.
3. **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.
