UE4 行为树资料

Composites

Select 选择

从左往右执行其子节点,直到一个达成,则 Select 达成并返回上层,否则失败并返回上层

Sequence 队列

从左往右执行其子节点,直到一个失败,则 Sequence 失败并返回上层,否则达成并返回上层

Simple Parallel 模拟并行

包含一个main task和一个sub tree, main task支持一个 Task 节点,用于执行一个主线行为,sub tree 支持一个行为树,伴随 main task 执行,返回结果是main task的执行结果

属性

Apply Decorator Scope 应用装饰器范围:all decorator in Branch Below will be removed when execution flow leaves

装饰器在分支下 will be 删除 when 执行流离开

Task

Task 节点用于执行具体的动作,引擎内置的 Task 常用的有 Wait 、 Move To 、 Is At Location 等等,Task 一般是自行实现的AI具体的行为逻辑,其中的代码与普通蓝图代码一样

Task 中的常用事件

  • Event Receive Execute / Event Receive Execute AI
    定义该 Task 的主体逻辑代码,如果没有特殊需求,则必须以 Finish Execute 节点结束,因为只有 Finish Execute 节点才能向上层返回执行结果,否则该 Task 如果不被打断将不会执行完成

如果同时存在 Event Receive Execute 和 Event Receive Execute AI 两个事件,优先执行 Event Receive Execute AI 事件

  • Event Receive Abort / Event Receive Abort AI
    当前任务被打断时触发该事件,用来处理突发情况对当前行为的影响,如果没有特殊需求,则必须以 Finish Abort 节点结束,以结束该任务节点的执行

如果同时存在 Event Receive Abort 和 Event Receive Abort AI 两个事件,优先执行 Event Receive Abort AI 事件

Task节点

官档:http://api.unrealengine.com/CHN/Engine/AI/BehaviorTrees/NodeReference/Tasks/index.html

MoveTo

  • ReachTest Includes Goal Radius
    半径于AI胶囊将会增加到截值于AI和目标位置之间在目的地搜索测试时

radius of ai's capsule will be added to threshold between ai and goal location in destination reach test

  • allow partial path
    允许部分路径:使用不完整的路径在目标无法到达时

use incomplete path when goal can't be reached

  • allow partial path
    允许部分路径:如果已设置,则当选择执行此任务但该任务已在运行时,将放弃任务搜索。

if set,task search will be discarded when this task is selected to execute but is already running

  • observed blackboard value tolerance
    观察黑板值公差:如果任务预期对由BB键表示的位置的更改做出反应,此属性可用于调整机制的灵敏度,建议值小于可接受的半径。

if task is expected to react to changes to location represented by bb key this property can be used to tweak sensitivity of the mechanism,value is recommended to be less then acceptableradius

Decorator 装饰器

Decorator 类型的节点用作条件判断(类似于程序中的基本流程控制),附着于 Composites 或 Task 节点上
官档:http://api.unrealengine.com/CHN/Engine/AI/BehaviorTrees/NodeReference/Decorators/index.html

Observer Aborts

  • None 不中止执行。
  • Self 中止 self,以及在此节点下运行的所有子树
  • Lower Priority 中止此节点右方的所有节点
  • Both 终止 self、此节点下运行的所有子树、以及此节点右方的所有节点

Composite

可内部自定义逻辑组合用于最后的判断:节点是否执行
新建的Decorator,重写perform condition这个函数就可做到与Composite相同的功能。
https://www.cnblogs.com/timy/p/9047961.html

Services

Services 附着在 Composite 节点上,只要其分支节点被执行,它们便将按所定义的频率执行。它们常用于检查和更新黑板。它们以行为树系统的形态取代了传统平行节点
可在行为树图表编辑界面添加自定义的Service,在Service中添加若干Blackboard Key Selector类型的引用变量暴露出来并编译,然后将Service附着在Composites或者Task节点上,在节点上点击已附着的Service,在其属性栏中为其中的变量指认黑板上的键,然后在Service中编写逻辑代码对已指认的变量进行更新

Service中的常用事件

  • Event Receive Search Start / Event Receive Search AI
    在任务搜索进入树的分支时被调用。比如有一个父节点A,其下面有两个子节点B和C,当任务搜索进入A时调用A的Service中的Search Start,如果A完成或者被打断,当任务搜索进入B时,将再次调用A的Service中的Search Start

如果同时存在 Event Receive Search Start 和 Event Receive Search Start AI 两个事件,优先执行 Event Receive Search Start AI 事件

  • Event Receive Activation / Event Receive Activation AI
    在某节点从非活动子树的一部分变为活动子树的一部分时触发

如果同时存在 Event Receive Activation 和 Event Receive Activation AI 两个事件,优先执行 Event Receive Activation AI 事件

  • Event Receive Deactivation / Event Receive Deactivation AI
    在某节点从活动子树的一部分变为非活动子树的一部分时触发,如果附着于Task上,节点离开不会触发,附着于Composites上可以触发。

如果同时存在 Event Receive Deactivation 和 Event Receive Deactivation AI 两个事件,优先执行 Event Receive Deactivation AI 事件

  • Event Receive Tick / Event Receive Tick AI
    当Service所在的节点是活动子树的一部分时,Tick事件将以指定的频率调用,Tick的触发时间间隔由所在Service的Interval和Random Deviation属性共同决定,Interval指定基础时间间隔,Random Deviation指定在基础时间间隔上的随机误差

如果同时存在 Event Receive Tick 和 Event Receive Tick AI 两个事件,优先执行 Event Receive Tick AI 事件

总结

Composites类似于分支,Decorator类似于分支的判断,Task类似于Actor的动作,Services控制变量的值。
行为树操作黑板,Pawn操作黑板,动画蓝图操作黑板,抽像出了一层
使用行为树可使行为逻辑 直观,复用,可扩展,好维护。

原代码

例:BTTask_MoveTo----文档上查不到属性,因属性不是Public
UBTTaskNode ---->Task相关程序

相关网址

行为树历史
EQS与行为树
操作

原文地址:https://www.cnblogs.com/mattins/p/9269993.html