The Sequence node executes its children in order, from left to right. If any of the children return Failure
, the Sequence node stops execution and also returns Failure
. If all children return Success
, the Sequence node returns Success
.
The logic is as follows - if the 1st or 2nd check returns Failure
, the skill won't be cast. If both return Success
, the character will attempt to apply the skill.
Usually used in combination with the Selector node.
Nodes can be arranged however you like, as long as you remember that the traversal will be from left to right.
Here's what's happening - first, we use the Sequence(1) node, which combines another Sequence(2) and a Selector(5).
Sequence(2) handles checks like "Can we attack at all?", meaning we are alive and have a target selected. In real examples, checks for HP, being in a city, and so on can also be added here. If any of the checks fail, the tree moves to the next cycle without attempting an attack.
If we are alive and have a target, the next step is to decide "How exactly will we attack the selected target?".
For simplicity, there are only 2 options here:
In real scenarios, the rotation itself can be much more complex - resource checks (HP/MP/cooldowns), prioritizing the current target (if the target has low HP, there's no point in using a strong skill), and so on need to be considered.
Failure
, the Sequence returns Failure
.Success
, the Sequence returns Success
.Running
, the Sequence remembers it and continues execution from that point in the next update.Using the Sequence node allows for creating sequential chains of actions in behavior trees where the order of task execution is important.
Note! Sequence stops at the first node that returns Failure, while Selector stops at the first node that returns Success.