BOB JELTES
GAMES PROGRAMMER
Implementing your behavior tree
Now that we’ve made a behavior tree, let’s get it to work in the game.
Setting up the scene
-
Create a capsule game object in the scene
-
Add the Behavior Tree Executor component
-
Assign the behavior tree you've made to the Behavior field
Override blackboard
Observe that a new section just appeared in the inspector: the blackboard.
This blackboard holds variable overrides. When looking for a variable, the behavior will first search this blackboard for overrides, and then the original blackboard.
This allows us to create unique settings for this agent, or to provide scene references like a game object target.
Creating a target
Let’s create a target cube to put into this variable override.
-
Create a 3D cube and call it “Target Cube”
-
Select the agent
-
Drag the Target Cube into the value slot of the Target variable.
Action!
We are now ready to see the behavior in action.
You should see a green line is drawn between the agent and the target.
Blocking the view
But... not much else is happening.
Let’s place a wall between the agent and the target.
Now the line turns red and is interrupted when the wall obstructs the view!
And we’re done! You have just created your own behavior tree.