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

Implementing Blackboard Key Selectors

You will utilize Key Selectors to create flexible, reusable tasks that can target different Blackboard keys dynamically at runtime.

In this lesson, you will learn how to create highly reusable Behavior Tree tasks by using Blackboard Key Selectors to dynamically target data keys at runtime.

The Problem: Hardcoding Keys

When you create a custom Blueprint task, you might be tempted to hardcode the name of a Blackboard key—for example, "TargetActor." While this works for one specific task, it makes your code rigid. If you want to use the same logic for "Enemy," "LastKnownLocation," or "PatrolPoint," you would have to duplicate the entire task.

The Solution: Blackboard Key Selectors

A Blackboard Key Selector acts as a variable proxy within your custom task. Instead of typing in a string name, you add a variable of type Blackboard Key Selector to your Blueprint and ensure the Instance Editable (eye icon) is set to true.

When you place this task in your Behavior Tree, the details panel will expose a dropdown menu populated by all the keys currently defined in your Blackboard Asset. This allows you to choose exactly which key the task should read from or write to without ever touching the underlying Blueprint code.

Implementing the Logic

Inside your Event Receive Execute AI node, you don't use the key name directly. Instead, you use the node Get Blackboard Value as Actor (or As Vector, etc.). You feed your Blackboard Key Selector variable into the Key input of these nodes.

// Logic flow for a custom task using a Key Selector
// 1. You drag your KeySelector variable into the graph.
// 2. You connect it to "Get Blackboard Value as Actor".
// 3. The task now dynamically fetches whatever is stored in the key 
//    selected by the designer in the Behavior Tree editor.

By using Key Selectors, you transform a "Find Enemy" task into a generic "Get Value from Blackboard" task that can be reused for any key type, dramatically reducing the size of your project’s Blueprint library and making your AI logic much easier to maintain.

Key Takeaway: Blackboard Key Selectors allow you to abstract specific Blackboard keys into dynamic variables, enabling a single task to operate on different data points simply by changing a dropdown selection in the Behavior Tree editor.