Key (Variable)

Basic info about keys in AI Tree

Keys are variables used to store data that can be accessed and modified by various nodes in the Behavior Tree. The Blackboard functions as a data storage system that allows NPCs (non-player characters) to access important information and use it for real-time decision-making.

Key Aspects of Keys in Blackboard:

  1. Types of Keys:

    • Keys can represent various types of data, such as:

      • Object: Refers to an object in the game world, such as a target or player.

      • Vector: Stores coordinates or positions in space.

      • Float: Holds floating-point numerical values, such as health or speed.

      • Int: Integer values, for example, for counters or levels.

      • Bool: Boolean values (true/false) for conditions.

      • String: Text data, such as names of objects or messages.

  2. Accessing Data:

    • Nodes in the Behavior Tree can read and modify the values of keys in the Blackboard. This allows NPCs to adapt to changing game conditions. For instance, if an NPC sees a player, it can update a key that holds a reference to the target, influencing its behavior.

  3. Usage in Behavior Trees:

    • Keys are often used in conjunction with decorators and tasks. For example, a decorator might check the value of a boolean key to determine whether the NPC should attack or flee. Tasks can update key values when the NPC reaches a specific target or performs an action.

  4. Configuration:

    • Keys in the Blackboard can be configured through the editor, where developers can create and manage keys, assigning them names and types, making them easier to use in the Behavior Tree.

Example of Usage:

Suppose you have an NPC that needs to chase a player. You could create a key in the Blackboard named "Target" with an object type. When the NPC sees the player, it updates this key to point to the player object. Then, the nodes in the Behavior Tree can use the value of the "Target" key to manage the NPC's movement and execute appropriate actions, such as attacking or seeking cover.

Thus, keys in the Blackboard are an essential tool for creating adaptive and intelligent NPC behavior, allowing them to interact with the world and respond to player actions.

Last updated