Selector
1 or 2 or 3
Selector is one of the basic nodes in behavior trees. It represents a composite node that executes its children sequentially from left to right until one of the children returns Success, or until all children return Failure.
Example of Use
The Selector node is useful when actions need to be executed in order of priority. If one action fails, the Selector moves on to the next action in the list.
-
Choosing to attack with a skill or a basic attack
The logic here is to check if we can attack with a skill (it's ready, enough MP, etc.). If yes, we use the skill and exit. If not, we use a basic attack.
Note that either a skill attack or a basic attack will be executed. That is, if the skill attack is successful, the tree won't even reach Execute Aura(2'). -
Skill Rotation - Selector + Sequence: Now let's build a complete rotation.
![c5do0cg[1].png](/_wiki/assets/b5b11f4af3ac2cc641ec6c7180a8f00e6f052ef6356bb5f7c5916704f971ea11/assets/c5do0cg%5B1%5D.png)
What's happening here - first, we use the Sequence(1) node, which combines another Sequence(2) and 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 included 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:
- if the Aura Is Active(7) skill is ready, we use Execute Aura(8), which may contain the same Send Sequence inside.
- if the skill is not ready, we use a basic attack.
In real scenarios, the rotation itself can be much more complex - resource checks (HP/MP/cooldowns) are needed, target priority can be considered (if the target has low HP, there's no point in using a strong skill), and so on.
Node Operation
- The Selector node executes its children in order, starting from the leftmost child.
- If any child returns
Success, the Selector also returnsSuccessand stops executing the remaining children. - If all children return
Failure, the Selector returnsFailure. - If all children return
Running, the Selector also returnsRunningand continues execution from where it stopped.
Don't confuse! Sequence stops at the first node that returns Failure, while Selector stops at the first node that returns Success.
