What is a blackboard in a behavior tree, and what problems appear when many nodes read and write it?
answer
- shared memory for the tree
- keys instead of node fields
- who writes, who reads
- stale, typo, contention
basics
~20 sA blackboard is a key-value store a tree's nodes share: sensors write facts such as the target or ammo, conditions and actions read them. It decouples nodes but hides data flow and invites stale values, key mismatches and write conflicts.
solid answer
~50 sA **blackboard** is a key-value store, usually one per agent, that holds what the AI currently knows: target, last known position, ammo, chosen cover point. Perception and game code write keys; conditions read them ("magazine empty?" reads `ammoInMagazine`), and actions read their inputs and write their outputs, so one "move to" action can be reused with any position key. A **shared** blackboard, for a squad, lets agents coordinate. Many implementations also let nodes **observe** a key and react when it changes. The problems come from that shared, untyped looseness: data flow is invisible, so nobody knows who writes a key; values go **stale** when nothing clears or timestamps them; string keys break silently on a typo or a type mismatch; and two writers race, such as two soldiers claiming the same cover. Typed key declarations, one writer per key, timestamps and atomic claims keep it manageable.
go deeper
Recall that a blackboard is a shared key-value memory for the tree: sensors write facts, conditions read them, and actions take key names as their inputs and outputs.
Explain why keys make nodes reusable, how per-agent and shared boards differ, and how observers let a key change trigger re-evaluation.
Show how you would trace a behaviour bug to a stale, missing or contested key, and the claim-and-release discipline that keeps a shared board safe.
Decide the team's rules for keys: declared types, one owner per key, expiry for decaying facts, and what may go on a squad board at all.
## What a blackboard is A **blackboard** is a key-value store that the nodes of a behavior tree share. It is the AI's working memory: what this agent currently knows and has decided. Typical keys for a squad soldier: - `targetActor` and `targetLastKnownPosition` - `ammoInMagazine` and `grenadeNearby` - `chosenCoverPoint` - `underFire`, with the time it was last set The name comes from the older blackboard architecture, in which independent specialists post partial results to a shared board and read each other's. In behavior trees it is simpler: a dictionary of named, typed-or-untyped values attached to the agent. ## Why trees use one Behavior-tree nodes are meant to be small and reusable. If a "move to" action had its destination wired in as a field, you would need one node per destination. With a blackboard: - **Inputs and outputs become key names.** "Move to" takes a key, so the same node moves to `chosenCoverPoint` in one subtree and `targetLastKnownPosition` in another. - **Producers and consumers are decoupled.** Perception writes `grenadeNearby`; a guard reads it. Neither knows the other exists. - **Nodes stay stateless about the world.** In most designs the tree holds execution state (which child is running) and the blackboard holds knowledge. Actions can keep private progress, but facts others need go on the board. - **Designers can inspect one place.** A debugger view of the blackboard explains a lot of behaviour at a glance. ## Scope: per agent and shared Most trees get a **per-agent** blackboard. Coordination needs something wider: a **squad** or team blackboard that several agents' trees read, holding shared facts such as the squad's target, who is reloading, and which cover points are taken. Some implementations chain them: a lookup that misses on the agent's board falls back to the squad's. | scope | holds | main risk | |---|---|---| | per agent | this NPC's perception and decisions | stale or uncleared keys | | shared (squad or team) | coordination facts and claims | two agents writing the same key | ## Observers Many implementations let a node **observe** a key: register interest and be told when its value changes. That turns the blackboard into the trigger for re-evaluation. When perception sets `grenadeNearby`, a guard watching that key can interrupt a running branch at once, instead of waiting for the next full evaluation. It is also a cost: every observer is bookkeeping, and a noisy key that flips often will interrupt and restart branches just as often. ## What goes wrong - **Invisible data flow.** Nothing in the tree's shape shows that "move to cover" depends on a key written by a perception routine elsewhere. When the soldier stands still, the bug may be in whoever forgot to write the key. - **Stale values.** `targetLastKnownPosition` stays set after the target died or after it was seen somewhere else, and the soldier goes on searching a corner nobody has stood in for a minute. - **Name and type mismatches.** With string keys, a typo in one node reads an empty key and silently fails a condition; one node writes a position where another expects an actor. - **Write conflicts.** Two writers disagree about one key, and the last write wins. On a shared board, two soldiers read "cover point free" on the same tick and both run to it. - **A global dumping ground.** Everything goes on the board "just in case", and the tree's dependencies become impossible to follow. ## Disciplines that help 1. **Declare keys** with a name and a type in one place, and validate trees against that declaration when they are loaded. 2. **Give each key one writer**, and write that owner down; readers never write. 3. **Timestamp or expire** facts that decay, such as a last known position, and clear keys when their subject is gone. 4. **Claim shared resources atomically**: write an owner into the shared entry before acting, and treat claimed entries as unavailable to everyone else; release the claim when the action is halted or finishes. 5. **Keep keys few and meaningful**, and use the board's debugger view as part of every behaviour bug report. Which facts are worth sensing, and how a cover point is scored, belong to perception and tactical reasoning; the blackboard only carries what they produce to the nodes that decide.
- How do you stop two soldiers on one squad blackboard from taking the same cover point?Make the claim atomic: the first soldier writes its identity as the owner of that cover entry before moving, and every soldier's selection skips entries with another owner. Release the claim when the soldier leaves, dies or has the move halted, or the point stays reserved forever.
- Why is a blackboard key with observers a double-edged tool?Observers let a guard react the moment a key changes rather than waiting for a full re-evaluation, which makes the NPC responsive and cheap to run. But a key that flips often aborts and restarts branches just as often, so noisy facts need smoothing or a minimum hold time before an observer acts on them.
- Blackboard keys are private to the node that wrote them.
- Reading from the blackboard is faster than reading a node's own fields.
- Any node may write any key; the last write is always the right one.
- A last known position stays valid until something overwrites it.
- A shared blackboard makes two agents' decisions automatically consistent.