MassBattleBPTaskSnapshot.h
Source/MassBattle/Public/Tasks/MassBattleBPTaskSnapshot.h
概述 Overview
BP 异步任务(AgentsMoveTo / AgentsChaseAttack)的快照记录类型,随 FEntitySnapshotPayload 传输。resync 时旧任务对象被终止,依据这些记录经任务模板重建(UMassBattleBPTaskTemplateBase——TemplateKey 解析模板 BP 类,由模板重新绑定 delegate,BP 事件处理器在 resync 后存活)。只存可同步数据:UObject 引用(actor、FlowField)存路径,恢复时本地 FindObject 解析。无同名 .cpp——纯数据声明,序列化由反射(UPROPERTY)驱动。
Snapshot record types for the BP async tasks (AgentsMoveTo / AgentsChaseAttack), carried in FEntitySnapshotPayload. On resync the old task objects are terminated and rebuilt from these records via the task template (UMassBattleBPTaskTemplateBase — TemplateKey resolves the template BP class, which re-binds the delegates so BP event handlers survive resync). Only sim-syncable data lives here: UObject references (actors, FlowFields) are stored as paths and resolved locally on restore. No same-name .cpp — pure data declarations, serialized by reflection (UPROPERTY).
结构体 Structs
单 agent 的任务运行状态记录:UniqueID(实体 UID,恢复时反解为句柄)承载 MoveTo 的每 agent 运行状态(解析目标 / 目标索引 / 卡住检测 / 挂起 / 自定义路径跟踪);ChaseAttack 复用上方卡住字段(失败语义一致),另有 bWasOnInterruptedTarget(软锁定中断边沿闩)。
Per-agent task runtime-state record: UniqueID (entity UID, re-resolved to a handle on restore) carries the MoveTo per-agent runtime state (resolved goal / goal index / stuck tracking / suspension / custom-path tracking); ChaseAttack reuses the stuck fields above (same fail semantics) plus bWasOnInterruptedTarget (soft-lock interrupt edge latch).
成员变量 Members
| 名称 Name | 类型 Type | 默认值 | 说明 Description |
|---|---|---|---|
UniqueID | int32 | -1 | Agent 实体 UID,恢复时反解为句柄。Agent entity UID, re-resolved to a handle on restore. |
ResolvedGoalLocation | FVector | ZeroVector | MoveTo 解析后的目标位置。MoveTo resolved goal location. |
GoalIndex | int32 | 0 | 目标数组索引。Index into the goal array. |
StuckCheckTimer | float | 0.0 | 卡住检测累计时长(两任务共用)。Stuck-check accumulated time (shared by both tasks). |
StuckCheckStartLocation | FVector | ZeroVector | 卡住窗口起点位置。Stuck-window start location. |
bStuckCheckStarted | bool | false | 卡住窗口是否已开启。Whether the stuck window is open. |
bIsSuspended | bool | false | MoveTo:是否被行为挂起。MoveTo: whether suspended by a behavior. |
CustomPathIndex | int32 | 0 | MoveTo 自定义路径索引。MoveTo custom-path index. |
CurrentWaypointIndex | int32 | 0 | 当前航点索引。Current waypoint index. |
PathDirection | int32 | 1 | 路径方向(+1 正向 / −1 反向,PingPong)。Path direction (+1 forward / −1 reverse, PingPong). |
bWasOnInterruptedTarget | bool | false | ChaseAttack 软锁定:是否曾在非任务目标上(中断边沿闩)。ChaseAttack soft lock: whether on a non-task target (interrupt edge latch). |
OriginTaskID | int32 | 0 | 手动任务合并(MergeAgentsMoveToTasks)的来源任务 ID——该 agent 最初属于哪个壳任务;执行体按此把每 agent 事件路由回壳。0 = 执行体原生 agent(未合并)。旧快照默认 0。Origin task ID for the manual task merge (MergeAgentsMoveToTasks) — which merged shell task this agent originally came from; the executor routes per-agent events back to it. 0 = native agent of the executor (no merge). Old snapshots default to 0. |
任务级快照记录:TaskType(MoveTo / ChaseAttack)选择重建工厂;MyTaskID 必须与服务器存活任务一致(fragment 所有权检测匹配);TemplateKey 是模板 BP 类路径(空 = C++ 直建 → 恢复为无绑定);MoveTo 配置区(目标类型/位置/Actor 路径/实体 UID、导航模式/流场路径/图层/自定义路径/失败条件/可中断)与 ChaseAttack 配置区(目标 UID、可中断,失败条件复用);共享可视化配置;运行状态(跟踪行、累计失败 UID、bSuccessFired 闩)与手动合并区(bMergedShell / ExecutorTaskID,配合每 agent 的 OriginTaskID)。
Task-level snapshot record: TaskType (MoveTo / ChaseAttack) selects the rebuild factory; MyTaskID must equal the surviving server task's (fragment ownership checks match); TemplateKey is the template BP class path (empty = C++ direct creation → restored unbound); the MoveTo config section (goal type/locations/actor paths/entity UIDs, nav mode/flow-field path/layer/custom paths/fail conditions/can-interrupt) and ChaseAttack config section (target UID, can-interrupt; fail conditions shared); shared visualization config; runtime state (tracking rows, accumulated failed UIDs, the bSuccessFired latch) plus the manual-merge section (bMergedShell / ExecutorTaskID, paired with the per-agent OriginTaskID).
成员变量 Members
| 名称 Name | 类型 Type | 默认值 | 说明 Description |
|---|---|---|---|
TaskType | EBPTaskSnapshotType | MoveTo | 任务类型。Task kind. |
MyTaskID | int32 | 0 | 确定性任务 ID,必须与服务器存活任务一致。Deterministic task ID, must match the surviving server task. |
TemplateKey | FName | — | 模板 BP 类路径(UMassBattleBPTaskTemplateBase 子类);空 = 恢复为无绑定。Template BP class path (UMassBattleBPTaskTemplateBase subclass); empty = restored unbound. |
GoalType | int32 | 0 | EMBMoveGoalType 以 int32 存储(0=Location 1=Actor 2=Entity)。EMBMoveGoalType as int32 (0=Location 1=Actor 2=Entity). |
Locations | TArray<FVector> | 空 | 目标位置数组(常规 Activate 后为空,重建时从 per-agent 值回填)。Goal locations (empty after normal Activate; refilled from per-agent values on rebuild). |
GoalActorPaths | TArray<FString> | 空 | 目标 Actor 路径,恢复时本地 FindObject 解析。Goal actor paths, resolved locally via FindObject on restore. |
GoalEntityUIDs | TArray<int32> | 空 | 目标实体 UID 数组。Goal entity UID array. |
NavigationMode | int32 | 0 | ENavMode 以 int32 存储。ENavMode as int32. |
FlowFieldPath | FString | 空 | 流场路径,恢复时本地解析。FlowField path, resolved locally on restore. |
FlowFieldLayer | FFlowFieldLayerHandle | — | 流场图层句柄。Flow-field layer handle. |
CustomPaths | TArray<FMBCustomPath> | 空 | 自定义路径数组。Custom path array. |
CustomPathMode | int32 | 0 | ECustomPathMode 以 int32 存储。ECustomPathMode as int32. |
FailConditions | FMBMoveFailCondition | — | 失败条件(两任务共用,语义一致)。Fail conditions (shared by both tasks, same semantics). |
bCanInterrupt | bool | false | MoveTo:行为是否可中断。MoveTo: whether behaviors can interrupt. |
TargetUID | int32 | -1 | ChaseAttack 目标 UID。ChaseAttack target UID. |
bBehaviorsCanInterrupt | bool | false | ChaseAttack 锁定模式(false = 硬锁,true = 软锁)。ChaseAttack lock mode (false = HARD, true = SOFT). |
Visualization | FAgentTaskVisualizationConfig | — | 共享可视化配置。Shared visualization config. |
TrackedAgents | TArray<FAgentTaskAgentStateRecord> | 空 | 每 agent 运行状态。Per-agent runtime state. |
AccumulatedFailedUIDs | TArray<int32> | 空 | 累计失败 UID。Accumulated failed UIDs. |
bSuccessFired | bool | false | 成功已触发闩(保证 OnAgentSuccess 至多一次)。Success-fired latch (guarantees OnAgentSuccess fires at most once). |
bMergedShell | bool | false | 手动合并(MergeAgentsMoveToTasks):true = 本记录是休眠合并壳——只持有委托 + 自己的失败累积,其 agent 存于执行体记录中(以 OriginTaskID 标记)。Manual merge (MergeAgentsMoveToTasks): true = this record is a dormant merged shell — it holds delegates + its own fail accumulator; its agents live in the executor's record (tagged with OriginTaskID). |
ExecutorTaskID | int32 | 0 | 壳的 agent 被并入的执行体任务 ID(仅 bMergedShell 时有效;恢复时 RebuildTasksFromSnapshot 据此把壳重绑到存活的执行体)。The executor task this shell's agents were merged into (valid only when bMergedShell; on restore RebuildTasksFromSnapshot uses it to re-bind the shell to the surviving executor). |
EBPTaskSnapshotType UENUM
任务快照类型,重建时选择对应工厂。
Task snapshot kind, selecting the rebuild factory.
| 值 Value | 说明 Description |
|---|---|
MoveTo | AgentsMoveTo 任务。AgentsMoveTo task. |
ChaseAttack | AgentsChaseAttack 任务。AgentsChaseAttack task. |
管线角色 Pipeline Role
纯数据声明,无同名 .cpp。消费方:UMassBattleSubsystem::CaptureTaskRecords(经任务的 CaptureSnapshot 填充)与 RebuildTasksFromSnapshot(按 TaskType 调 CreateMoveToTaskFromSnapshot / CreateChaseAttackTaskFromSnapshot);记录随 FEntitySnapshotPayload 跨端传输,由快照注册表驱动序列化。
Pure data declarations with no same-name .cpp. Consumers: UMassBattleSubsystem::CaptureTaskRecords (filled via the tasks' CaptureSnapshot) and RebuildTasksFromSnapshot (dispatches to CreateMoveToTaskFromSnapshot / CreateChaseAttackTaskFromSnapshot by TaskType); records travel cross-peer inside FEntitySnapshotPayload, serialized by the snapshot registry.