In this lesson, you will learn how to use the Parallel node in Behavior Trees to execute multiple AI actions at the same time, such as playing a search animation while simultaneously scanning for enemies.
The Concept of Parallelism
In a standard Sequence or Selector, your AI performs tasks one after another. If your "Search" task takes five seconds to play an animation, the AI won't do anything else—like updating its perception or checking the Blackboard—until that animation finishes. The Parallel node solves this by allowing one "Main" task to run while one or more "Background" tasks execute concurrently.
Implementing the Parallel Node
When you add a Parallel node to your Behavior Tree, you’ll notice it has two distinct types of child slots:
- Main Task: This is the primary branch. When this task finishes, the entire Parallel node completes.
- Background Tasks: These are additional branches that run alongside the Main task.
If you are creating a "Searching" state, your structure would look like this:
- Parallel Node
- Main Task:
PlayAnimation(The "Searching" loop) - Background Task:
RunService(A logic-heavy node that constantly updates your Blackboard with new potential targets)
- Main Task:
Important Considerations
You must define how the node finishes using the Finish Mode setting:
- Immediate: The Parallel node finishes as soon as the Main task is done, regardless of whether the background tasks are finished.
- Delayed: The node waits for both the Main task and all background tasks to finish before moving on to the next node in the tree.
By using Immediate mode, you can ensure that as soon as your search animation completes, the AI immediately switches to its next logic step, even if your background scanning task is still running. This keeps your AI feeling responsive and "alive" rather than waiting for every single background process to wrap up.
Key Takeaway: The Parallel node allows you to decouple secondary utility tasks (like scanning) from primary action tasks (like animations), preventing your AI from becoming "stuck" in a single state while waiting for background logic to conclude.