The AI Controller class we created will add both the Behavior Tree and the Blackboard that we created in the previous two recipes.
A Behavior Tree is connected to an AI Controller, which in turn is connected to a Character. We will control the behavior of Character through the Behavior Tree by entering Task and Service nodes in the diagram.
A Behavior Tree hosts six different types of node, as follows:
- Task: Task nodes are the purple nodes in the Behavior Tree that contain Blueprint code to run. It's something that the AI-controlled unit has to do (code-wise). Tasks must return either true or false, depending on whether the task succeeded or not (by providing a FinishExecution() node at the end).
- Decorator: A decorator is just a Boolean condition for the execution of a node. It checks a condition, and is typically used within a Selector or Sequence block.
- Service: This runs some Blueprint code when it ticks. The tick interval for these nodes is adjustable (it can run slower than a per-frame tick, for example, every 10 seconds). You can use these to query the scene for updates, a new opponent to chase, and so on. The Blackboard can be used to store queried information. Service nodes do not have a FinishExecute() call at the end of them.
- Selector: This runs all subtrees from left to right until it encounters a success. When it encounters a success, the execution goes back up the tree.
- Sequence: This runs all subtrees from left to right until it encounters a failure. When a failure is encountered, the execution goes back up the tree.
- Simple Parallel: This runs a single task (purple) in parallel with a subtree (gray).