行為樹中的"Observer Aborts"屬性以及相關
One critical thing you'll notice if you select either the "Needs Ammo" or "Has Enemy" nodes in the BotBehavior tree is that they are both set to "Observer Aborts" "Lower Priority". Our conditional decorators support event-driven changes to make the behavior tree more efficient. Rather than having to iterate over the entire tree constantly as in the most basic behavior trees, we can register for an event if a conditional changes that should cause the tree's execution flow to change.
If "Observer aborts" is "None", then only during traditional BT execution will the conditional check of a decorator matter. So for example, if you have a simple check such as "is Blackboard entry Enemy set?" (i.e. not NULL), it will only check as the execution moves through the node into the subtree. If later it becomes NULL in that subtree, execution won't instantly leave the subtree (though it might exit due to failure of some task that requires that value). Similarly, if execution is in a lower priority subtree, it won't instantly know that the condition for a higher priority task has been satisfied, so the lower priority task will continue until it succeeds or fails normally. Then, execution through the higher priority branch may discover that that task can be executed.
However, if you set "Observer Aborts" to "Self", then while execution remains in the subtree, if the status of that decorator changes, it will cause the tree to abort immediately. For example, if the Enemy becomes "Is Not Set" (NULL)), it will abort (basically failing up the tree).
If you set "Observer Aborts" to "Lower Priority", then while the execution is in a lower priority subtree, if the condition is satisfied such that execution can move into the higher priority subtree, then the lower subtree will abort immediately. So, if the behavior tree is doing the "Idle" behavior and the Enemy becomes set it will immediately abort the lower priority tree ("Idle") and begin the higher priority tree that was prevented by the "Has Enemy" node being false previously.
"Observer Aborts" "Both" means that it will abort both "Self" AND "Lower Priority" trees.
NOTE: If there are multiple nodes that are all set to abort "Lower Priority" (or "Both"), they will all have to be satisfied before the lower priority tree will be aborted. That way, you won't have to worry about separate value changes repeatedly aborting your lower priority tasks when the higher priority task can't actually execute.
To help visualize the "Self" and "Lower Priority" trees in the editor, if you select a specific decorator, it will highlight "Self" and/or "Lower Priority" nodes in the tree (depending on the "Observer Aborts" property). In the details view you can see the key which shows which color is Lower Priority (a light blue at the moment) and which is "Self" (currently a teal-green).
總的來說,Observer Aborts提供了中斷執行流的可能。
還有就是,你不用擔心這種情況: 等級高的節點設定了OnValueChanged或者OnResultChanged並且Aborts為Both,某個時間點監控的值發生改變了但是並沒有達到condition的要求,這時候你的Task並不會Abort掉。如果你的Task被Abort掉了,肯定是等級高的滿足了Conditon條件了並且可以被執行了。