3.0 KiB
3.0 KiB
BP_MoveInput
基本信息
- 类型: Blueprint (ActorComponent)
- 父类: UEndpointComponent
- 源文件: /Game/Blueprints/Component/BP_MoveInput.BP_MoveInput
- 模块: Content
功能概述
BP_MoveInput 是移动输入端点组件,持有对 CharacterMovementComponent 的引用(通过 CharMove 变量),将指令系统中的移动指令转化为实际的角色移动。
设计用意
BP_MoveInput 是指令系统和 UE 移动系统之间的桥梁。它持有 CharMove (CharacterMovementComponent*) 引用,在 OnCommandReceived 中接收移动指令(连续指令,如 "Command.Move"),从 FCommandPacket.ContinuousPayload.ContinuousValue 提取移动向量,然后调用 CharacterMovementComponent 的移动接口。这种设计将输入系统和移动系统解耦——指令的生成、路由和执行分别由不同的组件负责。
职责范围
BP_MoveInput 负责接收移动指令并将其转换为 CharacterMovementComponent 的移动调用。移动向量通过连续指令的 ContinuousValue 传入,由 BP_MoveInput 提取并应用。指令的生成由 UCommandInputComponent 负责,指令的路由匹配由 UCommandRouter 负责。
项目内依赖
| 依赖项 | 关系 | 源文件 |
|---|---|---|
| UEndpointComponent | 父类 | CharacterControl 插件 |
| UCharacterMovementComponent | 引用 (CharMove) | 引擎内置 |
对外接口
- 蓝图变量:
CharMove(CharacterMovementComponent*) -- 持有对所属角色的 CharacterMovementComponent 引用,is_instance_editable,可在组件实例上配置
- 继承自 UEndpointComponent 的接口:
EndpointState(FEndpointState) -- 端点状态,含InterestedTags配置关注的移动指令标签(如 "Command.Move")OnCommandReceived(const FCommandPacket& Command)(BlueprintImplementableEvent) -- 收到移动指令时调用,在 EventGraph 中实现(node_count=22)OnEndpointStateChanged/OnCommandOutput-- 状态和输出委托
- 通过 EventGraph 的行为:
- 从
Command.ContinuousPayload.ContinuousValue提取移动向量 (FVector3f) - 调用
CharMove的移动接口将向量转化为实际角色移动
- 从
使用方法
- 作为 ActorComponent 添加到 BP_TestChar
- 设置
CharMove变量指向所属角色的CharacterMovementComponent - 配置
EndpointState.InterestedTags添加移动相关 GameplayTag(如 "Command.Move") - 设置
EndpointState.bIsContinuousFriendly = true(移动是连续指令) UCommandRouterComponent自动发现并注册本组件为端点- 当 EnhancedInput 产生移动输入 -> UCommandInputComponent 生成 FCommandPacket -> UCommandRouterComponent 按标签匹配 -> 本组件的 OnCommandReceived 收到指令 -> 从 ContinuousPayload.ContinuousValue 提取 FVector3f -> 调用 CharacterMovementComponent 执行移动
用例
- BP_TestChar 的组件,处理移动指令
- 通过
CharMove变量连接 CharacterMovementComponent,实现指令到移动的桥接