Course contentsShow
← Unity Game Development
Lesson 543 of 8288. Artificial IntelligenceFree lesson

Integrating Sensory Data into Blackboard Systems

You will pipe processed sensory inputs into a centralized Blackboard component to inform decision-making logic for AI behavior trees.

In this lesson, you will learn how to feed raw sensory information into your Blackboard so your Behavior Tree can transform environmental awareness into intelligent action.

The Bridge Between Senses and Logic

Up until now, you’ve built independent sensory systems—like Field of View cones or auditory triggers—and a robust Blackboard to store shared data. The missing link is the "Data Pipe." A sensory system shouldn't command the AI directly; instead, it should act as an observer that updates the Blackboard, leaving the Behavior Tree to decide how to respond.

Imagine your AI has a TargetPosition variable in its Blackboard. When your FOV component detects the player, it shouldn't trigger an animation; it should simply update that TargetPosition. The Behavior Tree, running its high-frequency tick, detects this change in the Blackboard and transitions from an "Idle" node to a "Chase" node.

Implementing the Data Pipe

To keep your architecture modular, use a simple observer pattern or direct reference update from your sensor component to the Blackboard component.

public class VisualSensor : MonoBehaviour
{
    public Blackboard blackboard; // Linked via Inspector

    void Update()
    {
        if (CanSeePlayer(out Vector3 playerPos))
        {
            // Inject the data into the blackboard
            blackboard.SetValue("LastSeenPosition", playerPos);
            blackboard.SetValue("IsTargetVisible", true);
        }
        else
        {
            blackboard.SetValue("IsTargetVisible", false);
        }
    }
}

Why Decouple?

By piping sensory data into the Blackboard rather than calling Behavior Tree methods directly, you gain two massive advantages:

  1. Consistency: Multiple sensors (sight, sound, touch) can all contribute to the same Blackboard keys. The Behavior Tree doesn't care how the TargetPosition was found, only that it is currently valid.
  2. Debugging: You can inspect the Blackboard component during runtime to verify if your sensory systems are reporting data correctly, regardless of what the AI is currently "doing" in its tree.

Your Behavior Tree remains the "brain" that reads the blackboard, while the sensors act as the "nerves" that constantly update the state of the world inside that shared memory.

Key Takeaway: Sensors should only act as data providers that write to the Blackboard, allowing the Behavior Tree to remain the sole authority for interpreting environmental information and driving AI logic.