Each Behavior Tree maintains a data structure called a Blackboard, that holds variables and values relevant to an AI agent. It can be regarded as the memory of the AI agent, and is used to decouple the data used in a Behavior Tree from its logic.
An agent's Blackboard can be accessed by any node to read/write data, during the execution of the Behavior Tree. However, since each agent maintains its own space of variables and values, Blackboard variables cannot be shared across different Behavior tree instances. The structure of an agent's Blackboard could be as follows:
(532, 23, 32)
(543, 12, 32)
(512, 21, 32)
Included within this page is a detailed look at the Blackboard interface, along with a C++ example showing how to use it.
CRYENGINE's Blackboard uses a key-value data structure, where keys are of the type BlackboardVariableId which is just a wrapper for the variable name. A 32-bit CRC is used codify variable names and speed up key comparisons in the Blackboard.
Constructing a BlackboardVariableId is as simple as calling the constructor which takes a single argument.
The Blackboard interface exposes three functions:
To demonstrate how the above functions are used, the following code retrieves a variable Health, which is then set to 100.0f.
Get The Blackboard
To retrieve the Blackboard of a specific Behavior Tree instance, the Blackboard is accessed through a blackboard class member in the UpdateContext parameter of any core Behavior Tree function (OnInitialize, Update, and OnTerminate).
To retrieve the blackboard of a specific AI agent, we use the function GetBehaviorTreeBlackboard from the BehaviorTreeManager, which accepts the Entity Id.
In the following example, a MoveToPosition node is created which allows us to move an AI agent to a specific position, that is stored in a variable in the Blackboard.
The node has a string data member m_bbVariableNameDestination, which specifies the name of the Blackboard variable that stores the destination of the agent. This variable name could be hard-coded, but ideally, it must be set on each tree to allow for flexibility.
Additionally, the value of this variable in the Blackboard could set by any other node. For example, we could have a node CalculateCoverPosition set the variable CoverPosition, which would then be used by the MoveToPosition node to move an agent to a cover position.
Blackboard entries can be displayed on screen during the execution of a Behavior Tree in Game Mode, by enabling the ai_ModularBehaviorTreeDebugBlackboard CVar. This however, only displays variables of types int, bool, char, float, double, string, Vec2 and Vec3 as shown.
The current Blackboard implementation has three limitations:
- Sandbox support: Blackboard usage is not supported on Sandbox, meaning it can only be used via C++.
- Shared variables: Each Behavior Tree instance has its own Blackboard, meaning Blackboard variables cannot be shared between different instances.
- Limited debug system: Only Blackboard entries of a specific subset of types are shown when debugging.
On This Page
- No labels