官术网_书友最值得收藏!

Composite

Composite nodes are at the core of the decision-making capabilities of Behavior Trees in Unreal, and understanding how they work is key.

There are three kinds of Composite nodes: Selector, Sequence, and Simple Parallel. The last one has been added recently, and you will find that by using a combination of Selectors and Sequences, you will be able to cover most of your cases. Here is how they work:

Selector: This kind of node will try to find one of its children to execute, which means it tries to find either a branch (so another Composite node attached as a child) or a Task (another child, but it is a leaf) to execute. So, the Selector starts from the left-most child node and tries to execute it. If it fails (either the Task failed to be executed, or the whole branch failed), then it tries the second left-most, and so on. If one of the children returns Success, which means that either the Task has been completed or a whole branch has been completed, then the Selector reports Success to its parent, and stop executing other children. On the other hand, if all the children of the Selector report a fail, then the Selector reports a fail to its parent as well. In the following screenshot, you can see what the Selector node looks like:

Sequence: This kind of node works a bit like the opposite of the Selector. To report a success to its parent, all of the Sequence's children must report a success. This means that the Sequence will start executing the left-most child node. If it is a success, it carries on with the second left-most, and so on if it is successful as well. If all the children until the right-most are a success, then the Sequence reports a Success to its parent. Otherwise, if just one the children fail, then the Sequence will stop executing its children, and report a fail to the parent. In the following screenshot, you can see what the Sequence node looks like:

Simple Parallel: This is a particular kind of Composite node, which is used in specific cases. In fact, it can only have two children. The left-most child must be a Task, whereas the right-most child can be either a Task or a Composite (thus giving birth to a sub-tree). The Simple Parallel starts to execute both its children in parallel, although the left-most is considered the main one. If the main one fails, it reports a fail, but if the main one succeeds, then it reports a success. Based on its settings, the Simple Parallel, once it has finished executing the main task, can either wait until the end of execution of the sub-tree or directly report success or fail the main one to its parent and stop executing the sub-tree. In the following screenshot, you can see what the Simple Parallel node looks like. Please note that it is possible to drag only two children, in which the left-most must be a Task (the purple block is the draggable area):

In this way, Composite nodes can "decide" which tasks to execute, based on what their children report (fail or success), and the Composite node reports back (either fail or success) to their parent. Even if the only-child of the root (which is a Composite node) reports back a success to the Root, then the tree has been executed with success. A good Behavior Tree design should always allow for success.

主站蜘蛛池模板: 吉木萨尔县| 沈阳市| 马尔康县| 东丽区| 米泉市| 新蔡县| 兰坪| 云浮市| 永吉县| 虞城县| 娄底市| 嘉善县| 涿州市| 天峨县| 家居| 大邑县| 依安县| 峨眉山市| 乌兰察布市| 甘德县| 萍乡市| 永宁县| 新乡市| 凯里市| 临澧县| 南投市| 汾西县| 珠海市| 申扎县| 永宁县| 手游| 武平县| 郓城县| 武冈市| 新丰县| 石狮市| 河南省| 唐海县| 运城市| 吕梁市| 民乐县|