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

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.

主站蜘蛛池模板: 蒲江县| 那曲县| 闵行区| 明光市| 丁青县| 和田县| 博客| 肇源县| 怀远县| 蕲春县| 德庆县| 漯河市| 会昌县| 松溪县| 小金县| 宁强县| 廉江市| 盐山县| 五家渠市| 大姚县| 阳东县| 盖州市| 措勤县| 神农架林区| 壤塘县| 宜兴市| 和政县| 赤壁市| 扶沟县| 灵丘县| 贵定县| 瑞金市| 德江县| 陵川县| 武夷山市| 孝感市| 桐梓县| 体育| 清新县| 西乡县| 库伦旗|