Course contentsShow
← Unreal Engine Game Development
Lesson 420 of 8806. AI, Navigation, and Decision MakingFree lesson

Applying Decorators for Conditional Logic

You will attach Decorators to nodes to enforce conditional checks that gate execution based on Blackboard key values.

In this lesson, you will learn how to use Decorators to gate your Behavior Tree logic, ensuring nodes only execute when specific Blackboard conditions are met.

The Role of Decorators

In a Behavior Tree, Composites (like Selectors or Sequences) define the structure of your AI's decision-making. However, they don't inherently know if an action is valid at any given moment. Decorators act as the "gatekeepers" of your tree. By attaching a Decorator to a node, you instruct the AI to perform a check against the Blackboard before it even attempts to run that node's children.

Implementing Blackboard Decorators

The most common implementation is the Blackboard Decorator. To use it, right-click a composite or task node in your Behavior Tree, select "Add Decorator," and choose "Blackboard."

Once added, you configure its properties in the Details panel:

  1. Blackboard Key: Select the key you want to monitor (e.g., TargetActor or IsAlerted).
  2. Key Query: Define the logic. For example, if you set this to "Is Set," the node will only execute if the AI has successfully identified a target.
  3. Flow Control: This is the most powerful setting. If you set Observer Aborts to "Self" or "Both," the Decorator will actively monitor the Blackboard. If the condition becomes false while the node is running, the AI will immediately stop that branch and move to the next valid option.

Concrete Example

Imagine a "Chase Target" sequence. You would attach a Blackboard Decorator to the parent Sequence node:

  • Blackboard Key: TargetActor
  • Key Query: Is Set
  • Observer Aborts: Self

Now, if your AI loses sight of the player and the Blackboard clears the TargetActor key, the Decorator will detect the change. The AI will instantly abort the chase sequence, allowing the Behavior Tree to fall back to an "Idle" or "Patrol" state rather than getting stuck trying to chase a null reference.

Key Takeaway: Decorators transform static trees into dynamic, responsive AI by enforcing strict Blackboard conditions that can force nodes to start or abort based on real-time data changes.