MassBattle Docsv1.19.20

UMassBattleBPTaskAgentsMoveTo

UCLASS Async Task

Source/MassBattle/Public/Tasks/MassBattleBPTaskAgentsMoveTo.h

概述 Overview

批量 Agent 移动命令异步蓝图节点(UBlueprintAsyncActionBase + FTickableGameObject)。在游戏线程写 FMoving / FNavigating(目标、所有权 ActiveMoveToTaskID、导航模式、流场覆盖),实际的寻路/RVO/物理由 MoveProcessor 并行执行;任务每 MassBattle tick 经 TickCheck 监控:目标类型支持 Location(地面 Z 自动抬升到 agent 中心)/ Actor(逐帧跟踪)/ Entity(逐帧跟踪,形状感知到达);导航模式支持 Individual / FlowField(可覆盖流场与图层,完成时零帧恢复)/ Custom(自定义路径,OneWay/Looped/PingPong);按 agent 状态分类为 成功(到达)/ 失败(死亡、卡住 AverageSpeed 低于阈值持续 StuckTimeLimit 且距目标在 FailRadius 内、目标失效)/ 被行为中断(bCanInterrupt 时挂起,行为结束恢复)/ 被新任务接管(所有权转移)并广播对应 delegate。锁步门控:网络会话中只能在 ExecuteNetCommand 内创建;快照采集/恢复(FAgentTaskSnapshotRecord)支持 resync 任务重建。任务合并:MergeTemplateMoveToTasks 把同一模板类创建的全部活跃任务按配置签名归组,每组并入最旧任务成为唯一执行体;被并入者退化为休眠壳——不再 tick,但其委托仍按每 agent 的 OriginTaskID 路由触发,fragment 所有权保持在执行体。两阶段 tick:Phase A 并行分类(不相交内存,并行==串行),Phase B 串行应用数组级副作用。

Batch-agent move command async Blueprint node (UBlueprintAsyncActionBase + FTickableGameObject). Writes FMoving / FNavigating on the game thread (goal, ownership ActiveMoveToTaskID, nav mode, flow-field override); the actual pathfinding/RVO/physics run in parallel in the MoveProcessor. The task monitors agents every MassBattle tick via TickCheck: goal types support Location (ground Z auto-lifted to agent center) / Actor (tracked per frame) / Entity (tracked per frame, shape-aware arrival); nav modes support Individual / FlowField (overridable field and layer, zero-frame restore on completion) / Custom (custom paths, OneWay/Looped/PingPong); agents are classified per frame as success (arrived) / fail (dead, stuck — AverageSpeed below threshold for StuckTimeLimit within FailRadius, goal invalidated) / interrupted by a behavior (bCanInterrupt: suspended, resumed when the behavior ends) / transferred to a newer task (ownership transfer), broadcasting the matching delegates. Lockstep gate: in networked sessions tasks may only be created inside ExecuteNetCommand; snapshot capture/restore (FAgentTaskSnapshotRecord) supports resync task rebuild. Task merging: MergeTemplateMoveToTasks groups all active tasks created from one template class by config signature and folds each group into its oldest task as the single executor; absorbed tasks become dormant shells — they no longer tick, but their delegates still fire, routed per-agent by OriginTaskID, while fragment ownership stays on the executor. Two-phase tick: Phase A classifies in parallel (disjoint memory — parallel == serial), Phase B applies array-level side effects serially.

继承 Inheritance

UBlueprintAsyncActionBase → UMassBattleBPTaskAgentsMoveTo (+ FTickableGameObject)

EMBMoveGoalType UENUM

移动目标类型,由 FMBMoveGoal::GoalType 使用。

Move goal type, used by FMBMoveGoal::GoalType.

值 Value说明 Description
Location移动到固定世界位置。Move to a fixed world location.
Actor移动到 Actor(每帧更新)。Move to an actor (updates each frame).
Entity移动到 Mass 实体(必须有 FLocating)。Move to a Mass entity (must have FLocating).

结构体 Structs

FMBMoveGoal USTRUCT (BlueprintType)

移动目标配置:目标类型 + 三选一的每 agent 目标数组(位置 / Actor / 实体),数量不足时复用最后一个(EditCondition 互斥显示)。

Move goal config: goal type plus one of three per-agent goal arrays (locations / actors / entities); if fewer than agents, the last element is reused (mutually exclusive via EditCondition).

成员变量 Members
名称 Name类型 Type默认值说明 Description
GoalTypeEMBMoveGoalTypeLocation目标类型。Goal type.
LocationsTArray<FVector>空每 agent 目标位置(Location 模式)。Per-agent target locations (Location mode).
GoalActorsTArray<AActor*>空每 agent 目标 Actor(每帧跟踪,Actor 模式)。Per-agent target actors (tracked each frame, Actor mode).
GoalEntitiesTArray<FEntityHandle>空每 agent 目标实体(必须有 FLocating,Entity 模式)。Per-agent target entities (must have FLocating, Entity mode).
FMBMoveNavigation USTRUCT (BlueprintType)

导航模式与相关设置:模式(Individual / FlowField / Custom)+ 流场与图层覆盖 + 每 agent 自定义路径与末端行为。

Navigation mode and related settings: mode (Individual / FlowField / Custom) + flow-field and layer overrides + per-agent custom paths and end behavior.

成员变量 Members
名称 Name类型 Type默认值说明 Description
ModeENavModeIndividual导航模式。Navigation mode.
FlowFieldAFlowField*nullptrFlowField 模式使用的流场;为空则用 agent 自身流场(覆盖 FlowFieldToUsePtr,任务结束恢复)。FlowField to use in FlowField mode; null uses the agent's own field (overrides FlowFieldToUsePtr, restored on task end).
FlowFieldLayerFFlowFieldLayerHandle无效流场层;无效时用流场默认层。Layer within the flow field; invalid uses the field's default layer.
CustomPathsTArray<FMBCustomPath>空每 agent 自定义路径(不足复用最后一个)。Per-agent custom paths (last reused when fewer).
CustomPathModeECustomPathModeOneWay走完路径后的行为。Behavior after reaching the path end.
FAgentsMoveToTrackingData struct (内部跟踪,非 USTRUCT)

每 agent 跟踪行:UniqueID、ResolvedGoalLocation(解析后的目标)、GoalIndex(目标数组索引)、StuckCheckTimer / StuckCheckStartLocation / bStuckCheckStarted(卡住检测)、bIsSuspended(被行为挂起)、自定义路径跟踪(CustomPathIndex / CurrentWaypointIndex / PathDirection)、手动合并来源 OriginTaskID(0 = 执行体任务的原生 agent;非 0 = 从该任务 ID 合并而来,逐 agent 事件路由到该壳的委托,fragment 所有权保持在执行体)。

Per-agent tracking row: UniqueID, ResolvedGoalLocation, GoalIndex (index into the goal array), StuckCheckTimer / StuckCheckStartLocation / bStuckCheckStarted (stuck detection), bIsSuspended (suspended by a behavior), custom-path tracking (CustomPathIndex / CurrentWaypointIndex / PathDirection), and the manual-merge origin OriginTaskID (0 = native agent of the executor task; non-zero = merged in from that task ID — per-agent events route to that shell's delegates while fragment ownership stays on the executor).

公开方法 Public Methods

AgentsMoveTo static UMassBattleBPTaskAgentsMoveTo*

主工厂。锁步门控:UMassBattleNetworkSubsystem::IsOffLockstep 为真(网络会话且不在命令执行内)时拒绝并返回 nullptr。创建实例、铸 MyTaskID(计数器为 UMassBattleSubsystem::NextMoveToTaskID,按 World 落位,跳过 0)、缓存全部参数;Location 模式把目标抬升到 agent 中心 Z(LiftGoalToAgentCenterZ);每 agent 建立跟踪行;工厂内即 RegisterTask(快照采集 tick 当帧创建的任务在引擎激活前就要被采到)。

Main factory. Lockstep gate: rejects with nullptr when UMassBattleNetworkSubsystem::IsOffLockstep is true (networked session outside command execution). Creates the instance, mints MyTaskID (counter is UMassBattleSubsystem::NextMoveToTaskID, world-scoped, skipping 0), caches all parameters; Location mode lifts goals to agent-center Z (LiftGoalToAgentCenterZ); builds a tracking row per agent; registers via RegisterTask inside the factory (a task created on the snapshot-capture tick must be captured before the engine activates it).

Input
参数 Param类型 Type说明 Description
WorldContextUObject*世界上下文。World context.
Agentsconst TArray<FEntityHandle>&要命令的 agent 数组,无效实体静默跳过。Agents to command; invalid entities silently skipped.
GoalsFMBMoveGoal移动目标配置(位置/Actor/实体)。Movement goal config (locations/actors/entities).
NavigationFMBMoveNavigation导航模式与相关设置。Navigation mode and settings.
FailConditionsFMBMoveFailCondition卡住检测设置;StuckTimeLimit=0 禁用。Stuck detection settings; 0 disables.
BehaviorsCanInterruptbool行为(攻击/追击等)是否可中断本任务;中断时触发 OnAgentInterrupt,行为结束恢复。Whether behaviors (attack, chase, etc.) can suspend this task; OnAgentInterrupt fires when suspended, movement resumes when the behavior ends.
VisualizationFAgentTaskVisualizationConfig逐帧可视化配置(默认关闭)。Per-tick visualization config (disabled by default).
Output

返回任务实例;锁步门控拒绝时返回 nullptr。副作用:铸任务 ID、缓存参数、注册任务。

Returns the task instance, or nullptr when the lockstep gate rejects. Side effects: mints the task ID, caches parameters, registers the task.

CreateAgentsMoveToTask static UMassBattleBPTaskAgentsMoveTo*

模板化创建:经模板实例(UMassBattleBPTaskTemplateBase 子类)创建任务、记录模板键、绑定 delegate(模板类 BP 绘制的 BindMoveToTask)。附加守卫:任务重建窗口(IsTaskRebuildInProgress)拒绝 BP 创建;工厂不得自行 Activate(async 节点展开会调用一次 Activate,双激活会杀死任务——Location 模式首次激活清空 Locations,第二次命中 "Goal array is empty")。

Template-based creation: creates the task via the template instance (UMassBattleBPTaskTemplateBase subclass), records the template key, and binds the delegates (BP-drawn BindMoveToTask on the template class). Extra guards: the task-rebuild window (IsTaskRebuildInProgress) rejects BP creation; the factory must NOT activate (the async node expansion calls Activate() once; double activation kills the task — Location mode empties Locations on first activate, the second hits "Goal array is empty").

Input
参数 Param类型 Type说明 Description
TemplateClassTSubclassOf<UMassBattleBPTaskTemplateBase>任务模板类。Task template class.
其余参数同 AgentsMoveTo与主工厂一致。Same as AgentsMoveTo.
Output

返回任务实例(已绑定模板 delegate);模板为空/未实现绑定/门控拒绝时返回 nullptr。

Returns the task instance (with template delegates bound), or nullptr when the template is null / binding unimplemented / gated.

MergeTemplateMoveToTasks static bool

按模板合并的蓝图节点:把同一模板类创建的全部活跃 MoveTo 任务按配置签名归组,每组并入该签名最旧(任务 ID 最小)的任务——同模板下不同参数的任务各自归组。零记账:无需任务对象、无需 agent 列表,是 CreateAgentsMoveToTask 在高频出兵流(RTS 兵营)中的天然搭档——每次出兵照常创建,随后调一次本节点,每次出兵的任务折叠为一个执行体。门控:与其它创建入口相同的锁步门控(IsOffLockstep),且任务重建窗口(IsTaskRebuildInProgress)内拒绝。候选集来自子系统注册表(注册表序 = 创建序,TemplateKey 穿越 resync),双端解析结果一致;签名比较逐位精确、任务 ID 经快照同步,分组确定。不要把 BindMoveToTask 的 Task 参数存进模板 BP 变量(模板变量是锁步变量,引用类型被跳过,resync 后变野引用,后续合并会发散)。注意:Location 目标模式下合并不同集合点的任务功能上安全(每个 agent 自带已解析目标,事件仍路由到各自来源任务的委托),但同集合点出兵归批可使事件批次的 agent 数组连续。

Template-based merge Blueprint node: groups ALL active MoveTo tasks created from one template class by config signature and folds each group into that signature's oldest task (lowest task ID) — tasks created with different parameters from the same template each get their own group. Zero bookkeeping: no task objects, no agent lists — the natural companion to CreateAgentsMoveToTask in high-frequency spawn flows (RTS barracks): create per-spawn, then call this once and every per-spawn task folds into one executor. Gated by the same lockstep gate as the other creation entries (IsOffLockstep), and rejected while a task rebuild is in progress (IsTaskRebuildInProgress). The candidate set comes from the subsystem registry (registry order = creation order, TemplateKeys survive resync), so both peers resolve the identical set; the signature comparison is bit-exact and task IDs are snapshot-synced, so the grouping is deterministic. Do NOT hold the Task param of BindMoveToTask in template BP variables (template variables are lockstep variables where reference types are skipped — a stored task object goes stale after resync and subsequent merges would diverge). Note: in Location goal mode merging tasks with different rally points is functionally safe (each agent carries its own resolved goal; events still route to each origin task's delegates), but batching same-rally spawns keeps agent arrays contiguous per event batch.

Input
参数 Param类型 Type说明 Description
WorldContextUObject*世界上下文。World context.
TemplateClassTSubclassOf<UMassBattleBPTaskTemplateBase>要合并其活跃任务的模板类(模板键 = 类路径)。Template class whose active tasks merge (template key = class path).
Output

返回是否至少合并了两个任务;候选不足两个(如该模板首批单位)返回 false,不是错误;锁步/重建门控拒绝时记 Error 日志并返回 false。副作用:兼容来源的 TrackedAgents 移入执行体并打 OriginTaskID 标记、来源退化为休眠壳(见 IsMergedShell)。

Returns true if at least two tasks merged; fewer than two candidates (e.g. the template's first spawn wave) returns false — not an error; lockstep/rebuild gate rejections log an Error and return false. Side effects: compatible sources' TrackedAgents move into the executor tagged with OriginTaskID; sources become dormant shells (see IsMergedShell).

IsMergedShell / GetExecutorTaskID bool / uint32 (const)

合并壳状态查询:IsMergedShell 在本任务被并入执行体后返回 true——本任务已休眠(不再 tick、不活跃),但其委托仍由执行体为其 agent 触发(按 OriginTaskID 路由);GetExecutorTaskID 返回作为合并壳时的执行体任务 ID(否则为 0)。

Merged-shell state queries: IsMergedShell returns true once this task was merged into an executor — it is dormant (no tick, inactive), but its delegates still fire for its agents (routed by OriginTaskID on the executor); GetExecutorTaskID returns the executor task ID while acting as a merged shell (0 otherwise).

Input

无参数。

No parameters.

Output

返回壳状态 / 执行体任务 ID(非壳时 0)。无副作用。

Returns the shell state / executor task ID (0 when not a shell). No side effects.

OnShellRebuilt / FinishShell void

壳的 resync 重建与终结路径,均由系统内部调用。OnShellRebuilt(Shell):resync 后重链重建壳——执行体与壳两条记录都重建完成后由 RebuildTasksFromSnapshot 调用,把壳重新挂回执行体的 MergedShells 注册表,剩余 agent 数由执行体 TrackedAgents 的 OriginTaskID 重新推导(对采集/重建顺序不敏感)。FinishShell:壳的终结路径——以壳自己的失败累积广播 OnTaskEnd、注销、标记可销毁;壳的最后一个 agent 结束时由执行体调用,或由 RebuildTasksFromSnapshot 处理孤儿壳记录(payload 中无执行体)。

Shell resync-rebuild and terminal paths, both called internally by the system. OnShellRebuilt(Shell): re-links a rebuilt shell after resync — called by RebuildTasksFromSnapshot once both the executor and shell records exist, re-attaching the shell to the executor's MergedShells registry; the remaining-agent count is re-derived from the executor's TrackedAgents OriginTaskIDs (robust against capture/rebuild ordering). FinishShell: the shell terminal path — broadcasts OnTaskEnd with the shell's own accumulated failures, deregisters, marks ready to destroy; called by the executor when the shell's last agent resolves, or by RebuildTasksFromSnapshot for an orphaned shell record (no executor in the payload).

Input
参数 Param类型 Type说明 Description
ShellUMassBattleBPTaskAgentsMoveTo*重建的休眠壳(仅 OnShellRebuilt;已在注册表中或无效则忽略)。The rebuilt dormant shell (OnShellRebuilt only; ignored if invalid or already registered).
Output

无返回值。副作用:OnShellRebuilt 追加壳注册表条目;FinishShell 广播 OnTaskEnd(按 UID 反解失败实体句柄)、清空失败累积与跟踪行、注销任务、标记可销毁(幂等释放托管层引用)。

No return value. Side effects: OnShellRebuilt appends a shell-registry entry; FinishShell broadcasts OnTaskEnd (failed handles resolved back from UIDs), clears the failure accumulator and tracking rows, unregisters the task, marks ready to destroy (idempotent managed-layer-ref release).

CreateMoveToTaskFromSnapshot static UMassBattleBPTaskAgentsMoveTo*

resync 快照重建入口(仅 UMassBattleSubsystem::RebuildTasksFromSnapshot 调用):同锁步门控(resync 恢复窗口绕过 IsOffLockstep),经 RestoreFromSnapshot 填充状态后返回。

Resync snapshot rebuild entry (called by UMassBattleSubsystem::RebuildTasksFromSnapshot only): same lockstep gate (the resync restore window bypasses IsOffLockstep), fills state via RestoreFromSnapshot and returns.

Input
参数 Param类型 Type说明 Description
WorldContextUObject*世界上下文。World context.
Snapshotconst FAgentTaskSnapshotRecord&任务快照记录。Task snapshot record.
Output

返回重建的任务实例(待显式 Activate);门控拒绝时 nullptr。

Returns the rebuilt task (awaiting explicit Activate), or nullptr when gated.

GetNextTaskID / SetNextTaskID static uint32 / static void

任务 ID 计数器访问器——经快照 payload 在双端同步。计数器按 World 落位(2026-09-12 PIE desync 修复起):位于 UMassBattleSubsystem::NextMoveToTaskID(每 World 一份),不再是本类的进程级 static——PIE 同时承载两个世界时,共享计数器会使 ActiveMoveToTaskID 按 World 分叉导致 hash desync。世界上下文取不到子系统时读取返回 0、写入无操作。

Task-ID counter accessors — synced across peers through the snapshot payload. The counter is world-scoped (since the 2026-09-12 PIE desync fix): it lives on UMassBattleSubsystem::NextMoveToTaskID (one per world), no longer a process-static on this class — with PIE hosting two worlds at once, a shared counter forked ActiveMoveToTaskID per world and desynced the hash. If the subsystem cannot be resolved from the world context, the read returns 0 and the write is a no-op.

Input
参数 Param类型 Type说明 Description
WorldContextconst UObject*世界上下文,用于解析 UMassBattleSubsystem。World context used to resolve UMassBattleSubsystem.
InNextuint32恢复时写回的下一个任务 ID(仅 SetNextTaskID)。Next task ID written back on restore (SetNextTaskID only).
Output

Get 返回当前计数器值(子系统无效时 0);Set 无返回值。副作用:Set 覆写 NextMoveToTaskID。

Get returns the current counter (0 if the subsystem is invalid); Set has no return value. Side effect: Set overwrites NextMoveToTaskID.

Activate virtual void

激活:校验目标数组非空(FlowField 模式除外)与自定义路径非空,预解析 Actor/Entity 目标;逐 agent 过滤无效/濒死实体;Custom 模式分配路径并设首航点为目标;置 AStarMovingToFlag + BPTaskMoveToFlag(bMoveToLocked = !bCanInterrupt);命令接管:重置 FBehaving 为 Idle、终止进行中的 Return、清行为旗标与残留索敌目标;写 Moving(ActiveMoveToTaskID / Goal / bMovingToGoal / MoveState=None)与 Navigating(RequestedNavMode,FlowField 模式覆盖流场与图层并快照恢复值,Custom → Direct);广播 OnTaskStart;清空 Locations 数组(已解析进跟踪行);记录可视化墙钟起点;注册 MassBattleTick。

Activation: validates non-empty goal arrays (except FlowField mode) and custom paths, pre-resolves Actor/Entity goals; filters dead/dying agents; Custom mode assigns paths and sets the first waypoint as the goal; sets AStarMovingToFlag + BPTaskMoveToFlag (bMoveToLocked = !bCanInterrupt); command takeover: resets FBehaving to Idle, terminates in-flight Return, clears behavior flags and the stale trace target; writes Moving (ActiveMoveToTaskID / Goal / bMovingToGoal / MoveState=None) and Navigating (RequestedNavMode; FlowField mode overrides the field and layer, snapshotting restore values; Custom → Direct); broadcasts OnTaskStart; empties the Locations array (already resolved into tracking rows); records the visualization wall-clock start; registers with MassBattleTick.

Input

无参数。

No parameters.

Output

无返回值。副作用:写被命令实体的 fragment、广播 OnTaskStart、注册 tick 驱动。

No return value. Side effects: writes commanded entities' fragments, broadcasts OnTaskStart, registers the tick driver.

RestoreActivateFromSnapshot void (private)

快照恢复激活路径(bRestoringFromSnapshot 时 Activate 走此分支):对重建实体复检(死亡/濒死语义同常规 Activate),仅补写快照注册表未覆盖的 fragment 字段(FlowField 覆盖写 ptr + _Previous 同写,防 MoveProcessor 变更检测触发假重载);绝不重初始化快照状态。重置可视化墙钟预算并注册 tick。

Snapshot-restore activation path (taken by Activate when bRestoringFromSnapshot): re-validates agents against rebuilt entities (same dead/dying semantics as normal Activate) and re-claims only fragment fields the snapshot registry does not cover (the FlowField override writes ptr + _Previous together to prevent MoveProcessor change detection from triggering a false reload); never re-initializes snapshot state. Restarts the visualization wall-clock budget and registers the tick.

Input

无参数。

No parameters.

Output

无返回值。副作用:过滤跟踪行、补写流场指针、注册 tick。

No return value. Side effects: filters tracking rows, re-writes flow-field pointers, registers the tick.

CaptureSnapshot void

采集当前运行状态到快照记录(注册表驱动,由 UMassBattleSubsystem::CaptureTaskRecords 调用):任务类型/ID/模板键、目标配置(Actor 存路径、Entity 存 UID、Location 为空——重建时从 per-agent 值回填)、导航配置、每 agent 运行状态(目标/卡住/路径跟踪)、累计失败 UID。

Captures current runtime state into a snapshot record (registry-driven, called by UMassBattleSubsystem::CaptureTaskRecords): task type/ID/template key, goal config (Actor paths, Entity UIDs, Locations empty — refilled from per-agent values on rebuild), navigation config, per-agent runtime state (goal/stuck/path tracking), and accumulated failed UIDs.

Input
参数 Param类型 Type说明 Description
OutRecordFAgentTaskSnapshotRecord&输出的快照记录。Output snapshot record.
Output

无返回值。副作用:OutRecord 被填充。

No return value. Side effect: OutRecord filled.

TerminateForResync void

resync 终止:退订 tick + 可选 OnTaskEnd(bBroadcastOnTaskEnd=false 用于将从快照重建的任务——它们会"重生",结束事件是假结束)+ 标记销毁,不写 fragment(fragment 状态由快照 blob 权威)。清空 TrackedAgents 使 GC 延迟的 BeginDestroy→Cleanup 零写入;注销任务。

Resync termination: deregisters the tick + optional OnTaskEnd (bBroadcastOnTaskEnd=false for tasks that will be rebuilt from the snapshot — they "respawn", the end event would be a false end) + ready-to-destroy, WITHOUT fragment writes (fragment state is snapshot-blob authoritative). Empties TrackedAgents so the deferred GC BeginDestroy→Cleanup pass writes nothing; unregisters the task.

Input
参数 Param类型 Type说明 Description
bBroadcastOnTaskEndbool是否广播结束事件(默认 true;重建任务传 false)。Whether to broadcast the end event (default true; false for rebuilt tasks).
Output

无返回值。副作用:清理任务状态并标记销毁。

No return value. Side effects: clears task state and marks for destruction.

RestoreFromSnapshot void

从快照记录恢复运行状态(由 CreateMoveToTaskFromSnapshot 调用):任务 ID 必须与服务器存活任务一致(fragment 所有权检测匹配);目标配置按类型重建(Actor 经 FindObject 路径解析、Entity 经 UID 反解、Location 从 per-agent 值回填);导航配置恢复;跟踪行直接填充不重新推导;注册任务。

Restores runtime state from a snapshot record (called by CreateMoveToTaskFromSnapshot): the task ID must equal the surviving server task's (fragment ownership checks match); goal config rebuilt per type (Actor via FindObject path resolution, Entity via UID, Location refilled from per-agent values); navigation config restored; tracking rows directly filled, no re-derivation; task registered.

Input
参数 Param类型 Type说明 Description
InWorldContextUObject*世界上下文。World context.
Recordconst FAgentTaskSnapshotRecord&快照记录。Snapshot record.
Output

无返回值。副作用:填充全部恢复状态,置 bRestoringFromSnapshot。

No return value. Side effects: fills all restored state, sets bRestoringFromSnapshot.

TickCheck void (private, UFUNCTION)

逐帧驱动(注册于 UMassBattleSubsystem::MassBattleTick)。Phase A 并行分类(MBParallelFor Unbalanced,每 agent 只写自身槽位 + 自身实体 fragment,不相交内存——并行==串行,确定性不依赖 bDeterministic):① 死亡/无效 → Fail;② 所有权转移(ActiveMoveToTaskID != MyTaskID)→ Transfer;③ 更新目标(FlowField 模式回读 Moving.Goal;Actor/Entity 从缓存解析,失效 → 在当前处落脚并 Fail);④ 调试绘制;⑤ 挂起/恢复(bCanInterrupt 时行为旗标存在 → 置 bMoveToSuspended 挂起,行为结束恢复并重新认领);⑥ 到达判定(自身 FMove::XY::AcceptanceRadius,地面 3D / 飞行 2D;Entity 目标带碰撞体时形状感知——到胶囊表面距离;Custom 模式推进航点,末端按 OneWay/Looped/PingPong 处理);⑦ 卡住检测(AverageSpeed < StuckVelocityThreshold 累计 StuckTimeLimit,且距目标 ≤ FailRadius → Fail 并就地落脚)。Phase B 串行(倒序遍历)应用数组级副作用并广播 OnAgentSuccess / OnAgentFail / OnAgentInterrupt / OnAgentTransfer;重建可视化线段;全部解决后 Cleanup + FinishTask。

Per-frame tick driver (registered with UMassBattleSubsystem::MassBattleTick). Phase A parallel classification (MBParallelFor Unbalanced; each agent writes only its own slot + its own entity's fragments — disjoint memory, parallel == serial, determinism does not depend on bDeterministic): ① dead/invalid → Fail; ② ownership transfer (ActiveMoveToTaskID != MyTaskID) → Transfer; ③ goal update (FlowField mode reads back Moving.Goal; Actor/Entity resolved from cache, invalid → settle in place and Fail); ④ debug drawing; ⑤ suspend/resume (bCanInterrupt: behavior flags present → set bMoveToSuspended and suspend; behavior ends → resume and re-claim); ⑥ arrival check (own FMove::XY::AcceptanceRadius, 3D on ground / 2D when flying; shape-aware for Entity goals with a collider — distance to capsule surface; Custom mode advances waypoints, end handled per OneWay/Looped/PingPong); ⑦ stuck detection (AverageSpeed < StuckVelocityThreshold accumulating StuckTimeLimit, within ≤ FailRadius of the goal → Fail and settle in place). Phase B serial (reverse order) applies array-level side effects and broadcasts OnAgentSuccess / OnAgentFail / OnAgentInterrupt / OnAgentTransfer; rebuilds visualization lines; when all agents resolve → Cleanup + FinishTask.

Input
参数 Param类型 Type说明 Description
DeltaTimefloat模拟步长(秒)。Simulation step (seconds).
TickCountint32逻辑 tick 计数。Logic tick count.
Output

无返回值。副作用:写被命令实体的 fragment、广播四个逐帧 delegate、重建可视化、任务完成时清理。

No return value. Side effects: writes commanded entities' fragments, broadcasts the four per-frame delegates, rebuilds visualization, cleans up on completion.

SetupAgentFlags / ClearAgentFlags void (private, 各有 worker 安全重载)

置/清 AStarMovingToFlag + BPTaskMoveToFlag 并写 Moving.bMoveToLocked;ClearAgentFlags 带所有权守卫(仅当 ActiveMoveToTaskID == MyTaskID 或 0 时释放),恢复导航模式与任务前流场/图层(快照值直接恢复,零帧空窗)。worker 安全重载由调用方传入已解析的 UMassAPISubsystem*(线程上不做 UObject 查找)。

Sets/clears AStarMovingToFlag + BPTaskMoveToFlag and writes Moving.bMoveToLocked; ClearAgentFlags has an ownership guard (releases only when ActiveMoveToTaskID == MyTaskID or 0), restores the nav mode and the pre-task flow field/layer (snapshotted values restored directly, zero-frame gap). Worker-safe overloads take a caller-resolved UMassAPISubsystem* (no UObject lookup off the game thread).

Input
参数 Param类型 Type说明 Description
Entity (或 MA + Entity)const FEntityHandle目标 agent 实体。Target agent entity.
Output

无返回值。副作用:实体旗标与 fragment 被修改。

No return value. Side effects: entity flags and fragments mutated.

Cleanup / FinishTask void (private)

Cleanup:释放全部剩余 agent 的锁、退订 tick、注销任务、清可视化缓存;FinishTask:用累计失败 UID 广播 OnTaskEnd 并标记可销毁——所有终止路径的最后一步。

Cleanup: releases every remaining agent's lock, deregisters the tick, unregisters the task, clears visualization caches; FinishTask: broadcasts OnTaskEnd with the accumulated failed UIDs and marks ready to destroy — the final hop of every termination path.

Input

无参数。

No parameters.

Output

无返回值。副作用:清理注册与实体状态;广播结束事件。

No return value. Side effects: clears registrations and entity state; broadcasts the end event.

Tick / IsTickable / GetStatId FTickableGameObject 接口

引擎 tick 渲染路径:IsTickable 仅当有内容可绘制(bIsActive && CachedVizLines.Num() > 0);Tick 每渲染帧重新提交可视化线段(含墙钟预算闸门)——MassBattle tick 重建 CachedVizLines(逻辑 + 并行预计算),引擎 tick 重新提交,渲染频率高于模拟频率时不闪烁。

Engine-tick render path: IsTickable only when there is something to draw (bIsActive && CachedVizLines.Num() > 0); Tick re-submits the visualization lines every render frame (with the wall-clock budget gate) — the MassBattle tick rebuilds CachedVizLines (logic + parallel pre-compute), the engine tick re-submits, so rendering never blinks when the render rate exceeds the sim rate.

Input

无参数(Tick 收 float DeltaTime)。

No parameters (Tick takes float DeltaTime).

Output

无返回值(IsTickable 返回是否可 tick)。副作用:向世界线批处理提交可视化。

No return value (IsTickable returns tickability). Side effect: submits visualization to the world's line batcher.

管线角色 Pipeline Role

由蓝图经 AgentsMoveTo(或模板化 CreateAgentsMoveToTask)创建;锁步会话中必须由 ExecuteNetCommand 创建(门控见工厂)。TickCheck 注册在 UMassBattleSubsystem::MassBattleTick(命令执行后的帧内驱动),写 FMoving / FNavigating / FEntityFlagFragment;实际移动由 UMassBattleAgentMoveProcessor(SimStages[4])执行;行为抢占经 bMoveToSuspended / bMoveToLocked 与 Behavior 处理器互斥;resync 时经 FAgentTaskSnapshotRecord 采集/重建(UMassBattleSubsystem::CaptureTaskRecords / RebuildTasksFromSnapshot),模板实例重新绑定委托,任务 ID 计数器经 GetNextTaskID / SetNextTaskID 随快照 payload 同步。合并链路:执行体的 TickCheck 按 OriginTaskID 把合并 agent 的逐帧事件路由到来源壳的委托,壳的最后一个 agent 结束时由执行体调 FinishShell;resync 重建时 RebuildTasksFromSnapshot 先重建执行体与壳,再经 OnShellRebuilt 重链路由,payload 中无执行体的孤儿壳记录直接 FinishShell。

Created from Blueprint via AgentsMoveTo (or template-based CreateAgentsMoveToTask); in lockstep sessions it must be created by ExecuteNetCommand (gated in the factory). TickCheck registers with UMassBattleSubsystem::MassBattleTick (in-frame driver after command execution), writing FMoving / FNavigating / FEntityFlagFragment; actual movement runs in UMassBattleAgentMoveProcessor (SimStages[4]); behavior preemption is mutually exclusive with the Behavior processor via bMoveToSuspended / bMoveToLocked; on resync it is captured/rebuild via FAgentTaskSnapshotRecord (UMassBattleSubsystem::CaptureTaskRecords / RebuildTasksFromSnapshot), with the template instance re-binding delegates and the task-ID counter synced through the snapshot payload via GetNextTaskID / SetNextTaskID. Merge chain: the executor's TickCheck routes merged agents' per-frame events to their origin shell's delegates by OriginTaskID, and the executor calls FinishShell when a shell's last agent resolves; on resync rebuild RebuildTasksFromSnapshot rebuilds the executor and shells first, then re-links routing via OnShellRebuilt, while an orphaned shell record (no executor in the payload) goes straight to FinishShell.