效果

步骤
- 新建一个蓝图,父类选择"AI控制器"

这里命名为"BP_NPC_AIController",表示专门用于控制NPC的AI控制器

- 找到我们之前创建的所有NPC的父类"BP_NPC"

打开"BP_NPC",在类默认值中,将"AI控制器类"一项设置为"BP_NPC_AIController"

- 打开狮子蓝图"Character_Lion"

在事件图表中选中"事件开始运行"、"事件Tick"和构造函数,然后右键点击"将调用添加到父函数",这样子类就是自动调用父类的这些事件



由于我们不需要控制NPC移动,因此我们可以在事件图表中删除其他所有节点,只保留如下节点

- 回到"BP_NPC"中,在事件图表中添加如下节点,来获取对AI控制器的引用。这样"BP_NPC"的所有派生类中都可以直接使用变量"AIController_NPC"

- 再次回到狮子蓝图"Character_Lion"中,我们可以使用"移动到位置"节点来控制NPC移动到指定位置。注意这里需要取消勾选"Use Pathfinding"选项,因为此时我们还没有导航数据。

此时运行可以看到NPC狮子会朝着玩家移动
