Death.h
Source/MassBattle/Public/Fragments/Death.h
概述 Overview
死亡流程的 fragment 集合:配置 FDeath(延迟删除、淡出、动画策略、死亡时碰撞/网格参与、自杀特殊规则、死亡生成 Actor/FX/音效/战利品)、运行时状态 FDying(死亡过程计时、致死实体与方向、碰撞禁用倒计时)与两个标记 FDyingTag(死亡中)/ FDestroyingTag(销毁中)。
Death-flow fragments: config FDeath (despawn delay, fade-out, animation policy, dying-time grid/collision participation, suicide special rules, death spawns of Actor/FX/sound/loot), runtime state FDying (death timers, fatal entity and direction, collision-disable countdown) and two tags FDyingTag (dying) / FDestroyingTag (destroying).
FDeath USTRUCT
死亡配置 fragment(FA_MassBattleBaseFragment 派生)。所有字段为策划在 EntityConfig 中可调参数,运行时不变。经 MASS_FRAGMENT_ACCEPT_NOT_TRIVIALLY_COPYABLE 声明为不可平凡拷贝(含 TArray 成员)。
Death config fragment (derived from FA_MassBattleBaseFragment). All fields are designer-tunable EntityConfig parameters, constant at runtime. Declared via MASS_FRAGMENT_ACCEPT_NOT_TRIVIALLY_COPYABLE as not-trivially-copyable (contains TArray members).
成员变量 Members
| 名称 Name | 类型 Type | 默认值 | 说明 Description |
|---|---|---|---|
bEnable | bool | true | 是否启用死亡逻辑。Whether to enable death logic. |
DespawnDelay | float | 3.f | 死亡后删除的延迟时间(秒)。Delay before despawn after death (seconds). |
bCanFadeout | bool | true | 是否启用淡出效果。Whether to enable the fade-out effect. |
FadeOutDelay | float | 2.f | 淡出效果的延迟时间(秒)。Delay for the fade-out effect (seconds). |
bCanPlayAnim | bool | true | 是否播放死亡动画。Whether to play the death animation. |
bAnimAsDuration | bool | false | 勾选后使用死亡动画长度作为死亡行为时长(动画长度定义在 Animation fragment 里)。仅当 bCanPlayAnim 为 true 时可编辑。When enabled, uses the death anim length as the death behavior duration (defined in the Animation fragment). Editable only when bCanPlayAnim is true. |
AnimLength | float | 2.f | 死亡动画长度(秒)。仅当播动画且未用动画时长时可编辑。Death animation length (seconds). Editable only when animation is on and anim-as-duration is off. |
LifeSpan | float | -1.f | 寿命(秒),负值为无限长。Lifespan (seconds); negative for infinite. |
bExcludeFromHashGrid | bool | false | 启用时,Agent 死亡时将不会注册到哈希网格。If enabled, the agent will not be registered to the hash grid when dying. |
bCanFallDown | bool | true | 死亡的飞行单位坠落(重力)而非悬停。纯配置方案:坠落在移动处理器的 Z 决策点由已同步状态(DyingFlag)+ 本静态配置推导,Move.Z.bCanFly 不再被运行时改写——旧的死亡入口运行时改写配置 fragment 的做法在快照重建后丢失(FMove 从 DataAsset 模板恢复),导致重建的尸体悬停而服务器尸体坠落 → Z 分叉 → resync 循环(2026-08-15)。Dying flying agents fall to the ground (gravity) instead of hovering. Config-only: the fall is derived at the move processors' Z decision sites from synced state (DyingFlag) plus this static config, and Move.Z.bCanFly is never mutated at runtime — the legacy death-entry runtime write to the config fragment was lost on snapshot rebuild (FMove restores from the DataAsset template), leaving the restored corpse hovering while the server's corpse fell → Z divergence → resync loop (2026-08-15). |
bDisableCollisionWithAgent | bool | false | 启用时,Agent 死亡时将不会与其他 Agent 发生碰撞(禁用 PBD)。If enabled, the agent will not collide with other agents when dying (PBD disabled). |
DisableCollisionWithAgentDelay | float | 0.f | 进入死亡状态后多久(秒)禁用与其他 Agent 的碰撞。0 = 立即禁用。仅 bDisableCollisionWithAgent 为 true 时可编辑。Delay (seconds) after entering the dying state before agent-vs-agent collision is disabled. 0 = disable immediately. Editable only when bDisableCollisionWithAgent is true. |
bDisableCollisionWithObst | bool | false | 启用时,Agent 死亡时将不会与障碍物发生碰撞(禁用 PBD)。If enabled, the agent will not collide with obstacles when dying (PBD disabled). |
bInstantRemovalOnSuicide | bool | true | 如果 Agent 死于自杀,则直接移除。If the death cause is suicide, remove the agent at once. |
bDisableDeathSpawnOnSuicide | bool | true | 如果 Agent 死于自杀,不执行死亡生成逻辑。If the death cause is suicide, don't run death spawns. |
bForceGroundAlignment | bool | false | 启用时,死亡时强制启用地面对齐(俯仰和横滚匹配地面法线),无视 Move.Tilt 的 bAlignToGroundPitch/Roll 设置。If enabled, forces ground alignment (pitch and roll to match the ground normal) when dying, regardless of Move.Tilt's bAlignToGroundPitch/Roll settings. |
SpawnActor | TArray<FActorSpawnConfig> | 空 | 死亡时生成的 Actor 配置列表。Actors to spawn on death. |
SpawnFx | TArray<FFxConfig> | 空 | 死亡时生成的特效配置列表。Effects to spawn on death. |
PlaySound | TArray<FSoundConfig> | 空 | 死亡时播放的声音配置列表。Sounds to play on death. |
SpawnLoot | TArray<FLootConfig> | 空 | 死亡时生成的战利品配置列表。Loot to spawn on death. |
FDying USTRUCT
死亡运行时状态 fragment(FA_MassBattleBaseFragment 派生)。由死亡相关处理器逐帧推进:Time 累计死亡过程时间、DeathDissolveTime 累计消融时间、DeathAnimTime 累计动画时间;位域标志 bInitialized / bIsSuicide 标记流程阶段。默认构造器将三个位域显式清零。
Death runtime state fragment (derived from FA_MassBattleBaseFragment), advanced per frame by the death processors: Time accumulates the death process, DeathDissolveTime the dissolve time, DeathAnimTime the animation time; the bitfield flags bInitialized / bIsSuicide mark the flow stage. The default constructor zeroes all three bitfields explicitly.
成员变量 Members
| 名称 Name | 类型 Type | 默认值 | 说明 Description |
|---|---|---|---|
bInitialized | uint8 : 1 | 0 | 死亡过程已初始化标志。Death process initialized flag. |
bIsSuicide | uint8 : 1 | 0 | 是否为自杀。Whether the death was a suicide. |
Duration | float | 0.0f | 死亡过程持续时间(进入时按配置初始化)。Duration of the death process (seeded at entry from config). |
Time | float | 0.0f | 当前死亡过程已持续时间。Current elapsed time of the death process. |
DeathDissolveTime | float | 0.0f | 当前死亡消融时间。Current death dissolve time. |
DeathAnimTime | float | 0.0f | 当前死亡动画时间。Current death animation time. |
Instigator | FEntityHandle | — | 造成死亡的实体。The entity that caused the death. |
HitDirection | FVector3f | ZeroVector | 致命打击的方向。Direction of the fatal hit. |
DisableCollisionWithAgentTimer | float | 0.f | 死亡期间禁用与其他 Agent 碰撞前的剩余倒计时(秒)。死亡进入时由 Death.DisableCollisionWithAgentDelay 初始化,ReactionProcessor 中递减;>0 表示碰撞仍生效。Countdown (seconds) before agent-vs-agent collision is disabled while dying; seeded on dying entry from Death.DisableCollisionWithAgentDelay, ticked down in the ReactionProcessor; >0 means collision is still active. |
方法 Methods
带参构造:初始化标志、持续时间、消融/动画时间、致死实体与方向;注意 Time 恒被置 0.0f(无论传入的 InTime 参数如何——参数名与赋值不一致,源码如此)。
Parameterized constructor: initializes flags, duration, dissolve/anim times, instigator and hit direction; note Time is always set to 0.0f regardless of the passed InTime parameter (parameter name vs assignment mismatch — as in the source).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
InInitialzed | bool | 是否已初始化(写入 bInitialized)。Whether initialized (written to bInitialized). |
InDuration | float | 死亡过程持续时间。Death process duration. |
InTime | float | 传入但未使用——Time 恒置 0.0f。Passed but unused — Time is always set to 0.0f. |
InDeathDissolveTime | float | 死亡消融时间。Death dissolve time. |
InDeathAnimTime | float | 死亡动画时间。Death animation time. |
InInstigator | const FEntityHandle& | 致死实体句柄。Fatal entity handle. |
InHitDirection | const FVector3f& | 致命打击方向。Fatal hit direction. |
InIsSuicide | bool | 是否自杀(写入 bIsSuicide)。Whether suicide (written to bIsSuicide). |
Output
无返回值。副作用:全字段初始化。
No return value. Side effect: all fields initialized.
管线角色 Pipeline Role
FDeath / FDying 由行为/反应/移动处理器读取(grep 验证:MassBattleAgentBehaviorProcessor、MassBattleAgentReactionProcessor、MassBattleAgentMoveProcessor / MoveProcessorFP、MassBattleAgentSubsystem)。行为处理器推进死亡状态机并执行死亡生成(自杀路径按 bInstantRemovalOnSuicide / bDisableDeathSpawnOnSuicide 分支);DisableCollisionWithAgentTimer 在 ReactionProcessor 中递减(头注释声明)。
FDeath / FDying are read by behavior / reaction / movement processors (verified by grep: MassBattleAgentBehaviorProcessor, MassBattleAgentReactionProcessor, MassBattleAgentMoveProcessor / MoveProcessorFP, MassBattleAgentSubsystem). The behavior processor advances the death state machine and runs death spawns (suicide paths branch on bInstantRemovalOnSuicide / bDisableDeathSpawnOnSuicide); DisableCollisionWithAgentTimer is ticked in the ReactionProcessor (per the header comment).
补充说明 Notes
文件末尾的 FDisableDeathTag 为注释掉的预留 Tag 定义,当前未启用。
The commented-out FDisableDeathTag at the end of the file is a reserved tag definition, currently disabled.