Solo Tree
When you open the Solo behavior tree within Behavior Designer you’ll see (click to enlarge):
At this point the game is not running so the Behavior Tree Reference tasks are still visible within the tree. As soon as you hit play the tree will look like the following:
This tree contains a lot of tasks so for this section we’ll be taking it one step at a time, going through the tree in the same order that the behavior tree is evaluated. The first section that we are going to look at is the following:
Behavior trees are evaluated from top to bottom, left to right. The very first task that runs within the tree is the Sequence task. The Sequence task will run its first child task, the Reset task. Reset is used to reset all of the SharedVariables back to their default values. On first run the variables do not need to be reset but when the agent dies and respawns the behavior tree will start again from the beginning. It is here that we want to make sure all of the variables have a fresh start.
Immediately after the Reset task is the Wait task. The Wait task will delay the tree from executing for a very short amount of time which mimics the agent getting their bearing. The next child task that runs is the Random Probability conditional task. When the agent first spawns they may want to search for a power weapon (the rocket launcher). This random probability will introduce a randomness in determining if the agent should search for a power weapon. If Random Probability returns Success the Is Near Power Ammo task runs. If the agent is far away from a power weapon they should not search for it so this task performs that check. If Is Near Power Ammo returns Success then the Seek task will run. This task will seek towards the ammo position so the agent can pick up the power weapon.
In this child branch there were two conditional tasks which could return failure: Random Probability and Is Near Power Ammo. If either of these tasks return Failure then the Sequence task is also going to return Failure. The Return Success decorator is used to keep the tree running even if one of the child tasks return Failure.
The next task that runs is the Repeater. The behavior tree should continue to execute even if any of the child branches complete (successfully or unsuccessfully). The Repeater allows us to do just that. For example, if the agent kills the target then the attack branch will return Success. If there was no Repeater the behavior tree execution would then be over and the agent would just stand there. We don’t want this to happen so the Repeater will allow the agent to start searching for a new target.
If we look at the tree from a zoomed out view we’ll see that it has the following structure:
Each of the numbered branches is parented to the Selector task. The branches are arranged in a high to low priority so the Selector will run the branches from left to right. If a higher priority branch (a branch on the left) then the Selector will run the next branch to the right of the just failed branch. This allows us to organize the tree so high priority items (such as evading a grenade) are run before low priority items (such as searching for a target). The following branches are used within the Solo tree:
- Near Grenade
- Damaged
- Can See Target
- Search For Health
- Can Hear Target
- Search For Lost Target
- Search For Ammo
- Take Cover
- Search For Target
Some of these branches only contain a few tasks (such as Search For Health), while others contain multiple subtrees (such as Can See Target). For organizational purposes the rest of this overview is separated into sections based on the branch that they represent.