UMassAPIFuncLib
Source/MassAPI/Public/MassAPIFuncLib.h
概述 Overview
提供与 Mass 实体交互的实用函数蓝图函数库(UBlueprintFunctionLibrary)。覆盖:实体构建/销毁(立即与延迟,带完成回调)、查询匹配与批量获取、ForEach 游标迭代(供 ForEachMatchingEntities / ForEachEntityHandle K2 节点内部使用)、模板转换与实体快照、数学类型自动转换、统一 fragment 操作(CustomThunk + FGenericStruct 泛型载荷)与 Tag/Flag 操作。绝大多数函数经 UMassAPISubsystem::GetPtr(WorldContext) 取子系统后委托。文件尾部有一批 DeprecatedFunction 标注的旧 API,均转发到新名。
Blueprint function library (UBlueprintFunctionLibrary) for interacting with Mass entities. Coverage: entity build/destroy (immediate and deferred, with completion callbacks), query matching and batch fetch, ForEach cursor iteration (used internally by the ForEachMatchingEntities / ForEachEntityHandle K2 nodes), template conversion and entity snapshots, math auto-casts, unified fragment operations (CustomThunk + FGenericStruct generic payloads) and Tag/Flag operations. Most functions delegate through UMassAPISubsystem::GetPtr(WorldContext). The file tail holds a batch of DeprecatedFunction-flagged legacy APIs, all forwarding to the new names.
委托 Delegate
延迟命令完成时触发的动态委托,携带完成操作的实体句柄。多个函数经 AutoCreateRefTerm = "OnFinished" 暴露为可选回调。
Dynamic delegate fired when a deferred command finishes, carrying the entity handle of the completed operation. Several functions expose it as an optional callback via AutoCreateRefTerm = "OnFinished".
公开方法 Public Methods
立即执行 MassAPI 命令缓冲区中已排队的全部延迟命令:经 GetPtr(WorldContext) 取子系统并调用 FlushCommandBuffer()。需让排队的延迟操作当帧生效时调用。
Immediately applies all deferred commands queued in the MassAPI command buffer: fetches the subsystem via GetPtr(WorldContext) and calls FlushCommandBuffer(). Call it when queued deferred operations must take effect within the same frame.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文(DefaultToSelf)。World context (DefaultToSelf). |
Output
无返回值。副作用:共享命令缓冲被刷新执行。
No return value. Side effect: the shared command buffer is flushed.
IsValid 委托子系统的有效且活跃检查;两个比较操作符直接复用 FEntityHandle 的 == / !=。
IsValid delegates the subsystem's valid-and-active check; the two comparison operators reuse FEntityHandle's == / !=.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 仅 IsValid。IsValid only. |
EntityHandle / A / B | const FEntityHandle& | 要检查/比较的句柄。Handles to check / compare. |
Output
返回布尔(有效 / 相等 / 不等)。
Returns bool (valid / equal / not equal).
销毁单实体或批量实体,支持延迟。延迟单实体:压入 FMassDeferredDestroyCommand,刷新时实体有效才销毁并触发回调;立即路径直接 DestroyEntity 后回调。批量延迟:压入闭包,刷新时 BatchDestroyEntities 并对每个句柄触发回调;立即路径直接批量销毁后逐个回调。子系统中途不可用时静默返回(批量版本还要求数组非空)。
Destroys single or batched entities, with a deferred option. Deferred single: pushes an FMassDeferredDestroyCommand; on flush destroys only if valid, then fires the callback. Immediate path destroys then fires. Deferred batch: pushes a closure that runs BatchDestroyEntities and fires the callback per handle; immediate path destroys the batch then fires per handle. Returns silently when the subsystem is unavailable mid-flight (the batch version also requires a non-empty array).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle / EntityHandles | const FEntityHandle& / const TArray<FEntityHandle>& | 要销毁的实体(或数组)。Entity (or array) to destroy. |
bDeferred | bool | true 走命令缓冲,false 立即销毁。true queues via the command buffer, false destroys immediately. |
OnFinished | FOnMassDeferredFinished | 完成回调(批量版本对每个实体触发一次)。Completion callback (per entity for the batch version). |
Output
无返回值。副作用:实体被销毁(立即或刷新时),回调被触发。
No return value. Side effects: entities destroyed (immediately or on flush), callbacks fired.
基于模板数据的构建三件套。单实体延迟:立即 ReserveEntity,模板 Sort() 后快照 descriptors 压入 FMassDeferredCreateCommand(失败释放预留),刷新时 build + 写初值 + 回调,返回预留句柄;立即路径 BuildEntity 后回调。批量(数量)延迟:批量预留、批量 build 命令、逐个回调;立即路径 BuildEntities 后逐个回调。数组版本:每个模板建一个实体,空模板释放预留/返回空句柄;立即路径对空数据追加默认句柄。
Build trio from template data. Deferred single: immediately ReserveEntity, Sort() the template and snapshot descriptors into an FMassDeferredCreateCommand (releasing the reservation on failure); on flush build + initial values + callback, returning the reserved handle. Immediate path calls BuildEntity then fires. Deferred batch: batch-reserve, one build command, per-handle callbacks; immediate calls BuildEntities then fires per handle. Array version: one entity per template; empty templates release the reservation / append default handles on the immediate path.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
Quantity | int32 | 批量版本的数量(≤0 返回空)。Count for the batch version (≤0 returns empty). |
TemplateData / TemplateDatas | const FEntityTemplateData& / const TArray<FEntityTemplateData>& | 模板数据(或数组)。Template data (or array). |
bDeferred | bool | 是否延迟构建。Whether to defer the build. |
OnFinished | FOnMassDeferredFinished | 完成回调(批量版本对每个实体触发一次)。Completion callback (per entity for batch versions). |
Output
返回新建(或预留)实体的句柄(或句柄数组)。延迟模式下句柄立即预留、实体待刷新时完成创建,因此预留句柄可即刻使用;子系统/数据不可用时返回空句柄/空数组。
Returns the handle (or handles) of the newly created (or reserved) entities. In deferred mode handles are reserved immediately and the entities are fully created on flush, so the reserved handles are usable right away; empty on unavailable subsystem/data.
单实体查询匹配(委托 MassAPI->MatchQuery);批量版本把数组按查询拆分为匹配/不匹配两组(不匹配组含无效实体;子系统不可用时全部进不匹配组)。
Single-entity query match (delegates MassAPI->MatchQuery); the batch version splits the array into matching/unmatching groups (invalid entities go to unmatching; all go unmatching when the subsystem is unavailable).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle / EntityHandles | const FEntityHandle& / const TArray<FEntityHandle>& | 要检查的实体(或数组)。Entity (or array) to test. |
Query | const FEntityQuery& | 查询规则(All/Any/None 的 tag/fragment/flag)。Query rules (All/Any/None tags/fragments/flags). |
Output
单实体返回布尔;批量版本经 MatchingHandles / UnmatchingHandles 输出两组(先重置)。
Single returns bool; the batch version outputs MatchingHandles / UnmatchingHandles (both reset first).
查询计数与结果获取。实现(MassAPIFuncLib.cpp):Query.GetNativeQuery(EntityManager) 建原生查询;无旗标条件时快速路径(计数直接 GetNumMatchingEntities,获取直接转换);有旗标条件时慢路径——取全部匹配句柄后逐个按低/高位旗标过滤。GetMatchingEntities 警告:结果集可能巨大而拖累性能,批量获取仅建议原型期使用;正式逻辑请改用 GetNumMatchingEntities(数量查询)或 ForEach 循环。
Query count and result fetch. Implementation (MassAPIFuncLib.cpp): builds a native query via Query.GetNativeQuery(EntityManager); fast path when no flag conditions (count via GetNumMatchingEntities, fetch by direct conversion); slow path with flag conditions — fetch all matching handles then filter per-entity by low/high flags. GetMatchingEntities warns: the result set may be huge and hurt performance — batch fetch is for prototyping only; prefer GetNumMatchingEntities (count) or the ForEach loop for real logic.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
Query | const FEntityQuery& | 查询规则。Query rules. |
Output
分别返回匹配数量与匹配句柄数组;子系统/管理器不可用时返回 0 / 空数组。
Returns the matching count and handle array respectively; 0 / empty when the subsystem or manager is unavailable.
ForEach 游标迭代四件套(BlueprintInternalUseOnly,供 K2 节点内部使用)。Begin 版本:取子系统(不可用返回 -1),分配 NextForEachId++ 作为游标 ID,把实体列表(查询匹配结果或传入数组的拷贝)存入子系统的 EntityForEachStates 并置索引 0。Advance 版本:按 ID 取游标,越界/不存在时移除游标并返回 false;否则填充 OutElement / OutIndex 并推进索引。迭代完成自动清理游标状态。
ForEach cursor iteration quartet (BlueprintInternalUseOnly, used internally by the K2 nodes). Begin versions: fetch the subsystem (return -1 when unavailable), claim NextForEachId++ as the cursor ID, store the entity list (query matches, or a copy of the passed array) in the subsystem's EntityForEachStates with index 0. Advance versions: look up the cursor by ID; on missing/overrun remove the cursor and return false; otherwise fill OutElement / OutIndex and advance. Iteration end cleans up the cursor automatically.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
Query | const FEntityQuery& | 仅 BeginEntityForEach:迭代的查询。BeginEntityForEach only: query to iterate. |
Array | const TArray<FEntityHandle>& | 仅 BeginEntityHandleArrayForEach:迭代的句柄数组(安全拷贝)。BeginEntityHandleArrayForEach only: handle array to iterate (copied for safety). |
IterId | int32 | Advance 版本:游标 ID。Advance versions: the cursor ID. |
OutElement | FEntityHandle& | Advance 版本:输出的当前元素。Advance versions: output current element. |
OutIndex | int32& | Advance 版本:输出的当前索引。Advance versions: output current index. |
Output
Begin 返回游标 ID(失败 -1);Advance 返回是否还有下一个元素(结束自动移除游标状态)。
Begin returns the cursor ID (-1 on failure); Advance returns whether a next element exists (auto-removes the cursor state at the end).
模板转换:GetTemplateData 取子系统与 EntityManager,经 Template.GetTemplateData 编译蓝图模板为运行时数据(失败返回空句柄);Conv_TemplateToTemplateData 是 BlueprintAutocast 转换器,直接委托前者;IsEmpty_TemplateData 检查底层数据为空或无效(Data->IsEmpty(),空句柄视为空)。
Template conversion: GetTemplateData fetches the subsystem and EntityManager, compiling the Blueprint template into runtime data via Template.GetTemplateData (empty handle on failure); Conv_TemplateToTemplateData is a BlueprintAutocast converter delegating to it; IsEmpty_TemplateData checks the underlying data is empty or invalid (Data->IsEmpty(); empty handles count as empty).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文(前两个函数)。World context (first two functions). |
Template | const FEntityTemplate& | 源蓝图模板结构。Source Blueprint template struct. |
TemplateData | const FEntityTemplateData& | 仅 IsEmpty_TemplateData。IsEmpty_TemplateData only. |
Output
前两者返回编译后的模板数据;第三个返回是否为空/无效。
The first two return the compiled template data; the third returns whether it is empty/invalid.
实体快照:把活跃实体的完整 composition(全部 tag、带当前值的 fragment、共享/常量共享 fragment)与旗标(拆解为 Flags 数组以支持与 GetTemplateData 往返)捕获为蓝图友好的 FEntityTemplate。实现细节(SnapshotEntityToTemplate):FEntityFlagFragment 被跳过并从位掩码拆解;单实体版本输出 bSuccess(子系统/管理器/实体不可用时记警告并置 false);批量版本跳过无效实体并记警告(结果数组可能短于输入)。
Entity snapshot: captures a live entity's full composition (all tags, fragments with current values, shared/const-shared fragments) plus flags (decomposed into the Flags array for round-trip compatibility with GetTemplateData) into a Blueprint-friendly FEntityTemplate. Implementation details (SnapshotEntityToTemplate): FEntityFlagFragment is skipped and decomposed from the bitmask; the single version outputs bSuccess (warns and sets false when the subsystem/manager/entity is unavailable); the batch version skips invalid entities with a warning (the result may be shorter than the input).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle / EntityHandles | const FEntityHandle& / const TArray<FEntityHandle>& | 要快照的实体(或数组)。Entity (or array) to snapshot. |
bSuccess | bool& | 仅单实体版本:输出快照是否成功。Single version only: output snapshot success. |
Output
返回填充了实体当前 composition 与值的 FEntityTemplate(或数组)。
Returns an FEntityTemplate (or array) populated with the entity's current composition and values.
双精度 → 浮点精度的自动转换器:Conv_DoubleToFloat(double → float)、Conv_VectorToVector3f、Conv_QuatToQuat4f、Conv_RotatorToRotator3f、Conv_TransformToTransform3f、Conv_Vector2DToVector2f、Conv_Vector4ToVector4f。实现均为对应类型的强制转换。
Auto-cast converters from double-precision to float-precision: Conv_DoubleToFloat (double → float), Conv_VectorToVector3f, Conv_QuatToQuat4f, Conv_RotatorToRotator3f, Conv_TransformToTransform3f, Conv_Vector2DToVector2f, Conv_Vector4ToVector4f. Implementations are plain casts between the corresponding types.
Input
各转换器取对应的双精度源值(如 double / FVector / FQuat / FRotator / FTransform / FVector2D / FVector4)。
Each converter takes the corresponding double-precision source (e.g. double / FVector / FQuat / FRotator / FTransform / FVector2D / FVector4).
Output
返回转换后的浮点类型值。
Returns the converted float-precision value.
统一设置实体上的 Fragment / SharedFragment / ConstSharedFragment,节点自动适配 InFragment 连接的结构的类型。蓝图函数体 checkNoEntry();实际逻辑在 Generic_SetFragment_Entity_Unified。分派:普通 Fragment——延迟时压入 FMassDeferredSetCommand 闭包(刷新时 AddFragmentInstanceListToEntity + 回调),立即时已有则 SetEntityFragmentValues 覆写、没有则 AddFragment,成功后回调;Shared/ConstShared——延迟不支持(记警告并置 bSuccess=false),立即时先移除旧值再经 GetOrCreateSharedFragment(内存) 去重添加;其它类型记警告。执行器 execSetFragment_Entity_Unified 用 P_GET_PROPERTY(FDelegateProperty) 读委托并做二进制安全转换。
Unified set of a Fragment / SharedFragment / ConstSharedFragment on an entity; the node auto-adapts to the type of the struct connected to InFragment. The Blueprint-facing body is checkNoEntry(); the real logic lives in Generic_SetFragment_Entity_Unified. Dispatch: plain Fragment — deferred pushes an FMassDeferredSetCommand closure (on flush AddFragmentInstanceListToEntity + callback), immediate overwrites via SetEntityFragmentValues when present or AddFragment when absent, callback on success; Shared/ConstShared — deferred unsupported (warning + bSuccess=false), immediate removes the old value then adds via GetOrCreateSharedFragment(memory); anything else logs a warning. The executor execSetFragment_Entity_Unified reads the delegate via P_GET_PROPERTY(FDelegateProperty) and converts it binary-safely.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle | const FEntityHandle& | 目标实体。Target entity. |
FragmentType | UScriptStruct* | fragment 的脚本结构。Script struct of the fragment. |
InFragment | const FGenericStruct& | 泛型载荷(CustomStructureParam),要设置的值。Generic payload (CustomStructureParam): the value to set. |
bDeferred | bool | 是否延迟(Shared 延迟不支持)。Whether to defer (unsupported for Shared). |
OnFinished | FOnMassDeferredFinished | 完成回调。Completion callback. |
Output
经 bSuccess 输出操作结果;失败含无效参数、子系统/实体不可用、Shared 延迟。副作用:实体 composition/值被修改。
Outputs the operation result via bSuccess; failure covers invalid args, unavailable subsystem/entity, and deferred Shared. Side effect: the entity's composition/values change.
统一设置模板数据中的 Fragment / SharedFragment / ConstSharedFragment(存在则覆盖,不存在则添加)。逻辑在 Generic_SetFragment_Template_Unified:写时复制——按目标类型分派重建(普通 Fragment 复制全部类型与初值后添加/覆写目标;共享版本跳过旧 T 后经 Manager 去重添加),最后整体替换 TemplateData。Chunk fragment 不支持按值设置(记警告并中止)。
Unified set of a Fragment / SharedFragment / ConstSharedFragment in Template Data (overrides when present, adds otherwise). Logic in Generic_SetFragment_Template_Unified: copy-on-write — rebuilds dispatching on the target type (plain Fragment copies all types and initial values then adds/overwrites the target; shared versions skip the old T and add deduped via the Manager), finally replacing TemplateData wholesale. Chunk fragments cannot be set by value (warns and aborts).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文(共享去重需要)。World context (needed for shared dedup). |
TemplateData | FEntityTemplateData& | 被修改的模板数据。Template data being modified. |
FragmentType | UScriptStruct* | fragment 类型。Fragment type. |
InFragment | const FGenericStruct& | 泛型值载荷。Generic value payload. |
Output
无返回值。副作用:模板数据被整体重建替换。
No return value. Side effect: the template data is rebuilt and replaced.
统一读取实体上的 Fragment / SharedFragment / ConstSharedFragment。逻辑在 Generic_GetFragment_Entity_Unified:按类型分派——Fragment 经 GetFragmentDataStruct、Shared 经 GetSharedFragmentDataStruct、ConstShared 经 GetConstSharedFragmentDataStruct,视图有效则 CopyScriptStruct 拷入输出并置 bSuccess=true;Chunk fragment 不支持经句柄读取(记警告);未知类型记警告。执行器先 InitializeStruct 初始化输出内存。
Unified read of a Fragment / SharedFragment / ConstSharedFragment from an entity. Logic in Generic_GetFragment_Entity_Unified: dispatches by type — Fragment via GetFragmentDataStruct, Shared via GetSharedFragmentDataStruct, ConstShared via GetConstSharedFragmentDataStruct; on a valid view it CopyScriptStructs into the output and sets bSuccess=true; Chunk fragments cannot be retrieved via entity handle (warns); unknown types warn. The executor InitializeStructs the output memory first.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle | const FEntityHandle& | 要读取的实体。Entity to read from. |
FragmentType | UScriptStruct* | 要取回的类型。Type to retrieve. |
OutFragment | FGenericStruct& | 输出结构(泛型)。Output struct (generic). |
Output
经 OutFragment 输出数据、bSuccess 输出是否找到并拷贝成功。
Outputs the data via OutFragment and success via bSuccess.
统一从模板数据读取 Fragment / SharedFragment / ConstSharedFragment。逻辑在 Generic_GetFragment_Template_Unified:Fragment 在初值列表中按类型查找;Shared / ConstShared 在共享值中按类型查找;找到且有效则拷贝并置 bSuccess=true。Chunk fragment 无值可取(记警告);模板为空或类型非法记警告。
Unified read of a Fragment / SharedFragment / ConstSharedFragment from Template Data. Logic in Generic_GetFragment_Template_Unified: Fragments searched by type in the initial values; Shared / ConstShared searched in the shared values; on a valid find it copies and sets bSuccess=true. Chunk fragments have no retrievable value (warns); empty templates or invalid types warn.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
TemplateData | const FEntityTemplateData& | 要读取的模板数据。Template data to read. |
FragmentType | UScriptStruct* | 要取回的类型。Type to retrieve. |
OutFragment | FGenericStruct& | 输出结构(泛型)。Output struct (generic). |
Output
经 OutFragment 输出数据、bSuccess 输出是否找到。
Outputs the data via OutFragment and success via bSuccess.
从实体移除 Fragment / SharedFragment / ConstSharedFragment。延迟路径仅支持普通 Fragment 与 Tag(压入 FMassDeferredRemoveCommand,刷新时校验后移除并回调);Shared/ConstShared 延迟不支持(记警告返回 false)。立即路径按类型分派:Fragment 移除后返回 true;Shared/ConstShared 返回引擎结果;Chunk 不支持(记警告);未知类型记警告。
Removes a Fragment / SharedFragment / ConstSharedFragment from an entity. The deferred path supports plain Fragments and Tags only (pushes an FMassDeferredRemoveCommand, validates then removes and fires on flush); deferred Shared/ConstShared is unsupported (warns, returns false). The immediate path dispatches by type: Fragments remove then return true; Shared/ConstShared return the engine result; Chunk unsupported (warns); unknown types warn.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle | const FEntityHandle& | 目标实体。Target entity. |
FragmentType | UScriptStruct* | 要移除的类型。Type to remove. |
bDeferred | bool | 是否延迟。Whether to defer. |
OnFinished | FOnMassDeferredFinished | 完成回调(成功时触发)。Completion callback (fired on success). |
Output
返回是否成功移除(非法类型/不支持路径为 false)。
Returns whether the removal succeeded (false for invalid types / unsupported paths).
从模板数据移除 Fragment / SharedFragment / ConstSharedFragment。写时复制重建(逻辑在 MassAPIFuncLib.cpp):复制全部内容,按目标类型跳过匹配项(Chunk 在类型复制循环中处理);未知类型记警告并中止。Tag 不受影响(注释说明 Tags 不被此函数移除)。
Removes a Fragment / SharedFragment / ConstSharedFragment from Template Data. Copy-on-write rebuild (logic in MassAPIFuncLib.cpp): copies everything, skipping matches of the target type (Chunk handled in the type-copy loop); unknown types warn and abort. Tags are unaffected (per source comment, Tags are not removed by this function).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
TemplateData | FEntityTemplateData& | 被修改的模板数据。Template data being modified. |
FragmentType | UScriptStruct* | 要移除的类型。Type to remove. |
Output
无返回值。副作用:模板数据被重建并失去该元素。
No return value. Side effect: the template data is rebuilt without the element.
统一存在性检查:实体版本按 IsChildOf 分派到 CONTAINS_FRAGMENT / CONTAINS_TAG / CONTAINS_SHARED / CONTAINS_CONST_SHARED / CONTAINS_CHUNK(注意同时覆盖 Tag);模板版本经 TEMPLATE_HAS_FRAGMENT / TEMPLATE_HAS_SHARED / TEMPLATE_HAS_CONST_SHARED 宏与 Chunk 位集检查。非法类型/空模板记警告并返回 false。
Unified presence checks: the entity version dispatches via IsChildOf to CONTAINS_FRAGMENT / CONTAINS_TAG / CONTAINS_SHARED / CONTAINS_CONST_SHARED / CONTAINS_CHUNK (note it also covers Tags); the template version uses the TEMPLATE_HAS_FRAGMENT / TEMPLATE_HAS_SHARED / TEMPLATE_HAS_CONST_SHARED macros plus a Chunk bit-set check. Invalid types / empty templates warn and return false.
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 实体版本。Entity version. |
EntityHandle / TemplateData | const FEntityHandle& / const FEntityTemplateData& | 检查目标。Check target. |
FragmentType | UScriptStruct* | 要检查的类型。Type to check. |
Output
包含返回 true,否则 false。
Returns true when present, false otherwise.
Tag 六件套。实体版本要求类型是 FMassTag 派生(否则直接返回):AddTag_Entity / RemoveTag_Entity 延迟时压入 FMassDeferredAddCommand / FMassDeferredRemoveCommand(刷新时校验实体后操作并回调),立即时直接操作后回调;HasTag_Entity 委托子系统。模板版本 AddTag_Template 用 TEMPLATE_ADD_TAG、RemoveTag_Template 用 TEMPLATE_REMOVE_TAG、HasTag_Template 用 CONTAINS_TAG 检查模板 composition。添加目标已有的标签、或移除目标没有的标签,均为 no-op(幂等,无副作用)。
Tag sextet. Entity versions require the type derives from FMassTag (else early-return): AddTag_Entity / RemoveTag_Entity push FMassDeferredAddCommand / FMassDeferredRemoveCommand when deferred (validate then operate and fire on flush) or operate immediately then fire; HasTag_Entity delegates to the subsystem. Template versions use TEMPLATE_ADD_TAG / TEMPLATE_REMOVE_TAG / CONTAINS_TAG on the template composition. Adding a tag the target already has, or removing one it lacks, is a no-op (idempotent, no side effects).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 实体版本。Entity versions. |
EntityHandle / TemplateData | const FEntityHandle& / FEntityTemplateData& | 操作目标。Operation target. |
TagType | UScriptStruct* | Tag 类型。Tag type. |
bDeferred | bool | 实体写版本:是否延迟。Entity write versions: whether to defer. |
OnFinished | FOnMassDeferredFinished | 实体写版本:完成回调。Entity write versions: completion callback. |
Output
写操作无返回值;Has 版本返回布尔。
Writers return void; Has versions return bool.
旗标八件套(按 EEntityFlags)。实体版本:Set/Clear 延迟时压入 FMassDeferredSetCommand 闭包(刷新时校验实体与 FEntityFlagFragment 后修改并回调),立即时委托子系统对应方法后回调;Has 委托子系统;Get 委托 GetEntityFlags(仅低位)。模板版本:Set/Clear 先读模板中现有 FEntityFlagFragment 的低/高位,在临时 fragment 上修改后经 Generic_SetFragment_Template_Unified 写回(写时复制,『不存在则新增、存在则覆盖』);Set 在模板缺少 FEntityFlagFragment 时会按需新建该片段;Has 在模板初值中查找 fragment 并调其 HasFlag;Get 返回模板初值中 fragment 的低位掩码。所有版本越界(>= EEntityFlags_MAX)直接返回 false / 跳过。
Flag octet (by EEntityFlags). Entity versions: Set/Clear deferred push an FMassDeferredSetCommand closure (validate entity and FEntityFlagFragment, mutate and fire on flush), immediate delegate to the subsystem methods then fire; Has delegates the subsystem; Get delegates GetEntityFlags (low only). Template versions: Set/Clear read the template's existing FEntityFlagFragment low/high masks, mutate a temp fragment, write back via Generic_SetFragment_Template_Unified (copy-on-write; adds when absent, overrides when present); Set creates the FEntityFlagFragment as needed when the template lacks it; Has finds the fragment in the template initial values and calls its HasFlag; Get returns the fragment's low mask from the initial values. All versions return false / skip on out-of-range (>= EEntityFlags_MAX).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle / TemplateData | const FEntityHandle& / FEntityTemplateData& | 操作目标。Operation target. |
FlagToTest / FlagToSet / FlagToClear | EEntityFlags | 目标旗标。Target flag. |
bDeferred | bool | 实体 Set/Clear 版本。Entity Set/Clear versions. |
OnFinished | FOnMassDeferredFinished | 实体 Set/Clear 版本。Entity Set/Clear versions. |
Output
Has/Set/Clear 返回布尔(实体版本);Set/Clear 模板版本返回 void;Get 返回 int64 低位掩码。要求实体经模板添加 FEntityFlagFragment:实体/模板缺少该片段时 Has 恒返回 false,实体 Set/Clear 返回失败。
Has/Set/Clear return bool (entity versions); template Set/Clear return void; Get returns the int64 low mask. Requires the entity to have FEntityFlagFragment added via its Template: without the fragment Has always returns false (entity or template), and entity Set/Clear fail.
FName 版本:经 MassAPIFuncLib.cpp 的静态助手 LookupFlagByName 解析为 EEntityFlags——查 UMassAPIFlagSettings(UDeveloperSettings 派生的开发者设置)的 FlagRegistry,该注册表初始为空、由用户或集成插件填充;未注册返回 false / 静默跳过;解析成功后委托对应枚举版本(含 FEntityFlagFragment 前置要求)。
FName versions: resolve to EEntityFlags via the MassAPIFuncLib.cpp static helper LookupFlagByName, which looks up FlagRegistry on UMassAPIFlagSettings (a UDeveloperSettings-derived developer settings object; the registry starts empty and is populated by users or integrating plugins); unregistered names return false / silently skip; otherwise they delegate to the enum versions (including the FEntityFlagFragment prerequisite).
Input
| 参数 Param | 类型 Type | 说明 Description |
|---|---|---|
WorldContext | const UObject* | 世界上下文。World context. |
EntityHandle / TemplateData | const FEntityHandle& / FEntityTemplateData& | 操作目标。Operation target. |
FlagName | FName | 注册的旗标名。Registered flag name. |
bDeferred | bool | 实体 Set/Clear 版本。Entity Set/Clear versions. |
OnFinished | FOnMassDeferredFinished | 实体 Set/Clear 版本。Entity Set/Clear versions. |
Output
Has/Set/Clear 实体版本返回布尔;模板写版本返回 void。
Entity Has/Set/Clear return bool; template writers return void.
废弃函数 Deprecated Functions
文件尾部一批 Category = "MassAPI|ZDeprecated" + DeprecatedFunction 标注的旧 API(带 (Deprecated) DisplayName 与 DeprecationMessage),全部转发到新名:Tag 六件套(HasTag / AddTag / RemoveTag / HasTag_TemplateData / AddTag_TemplateData / RemoveTag_TemplateData)、Fragment 七件套(HasFragment / RemoveFragment / GetFragment / SetFragment / HasFragment_TemplateData / RemoveFragmentInTemplate / GetFragmentFromTemplate / SetFragmentInTemplate)、SharedFragment 五件套(RemoveSharedFragment / GetSharedFragment / SetSharedFragment / RemoveSharedFragmentInTemplate / SetSharedFragmentInTemplate)、ConstSharedFragment 五件套(RemoveConstSharedFragment / GetConstSharedFragment / SetConstSharedFragment / RemoveConstSharedFragmentInTemplate / SetConstSharedFragmentInTemplate)、Flag 六件套(HasEntityFlag / ClearEntityFlag / SetEntityFlag / HasTemplateFlag / ClearTemplateFlag / SetTemplateFlag)。头文件中源码注释标注缺失的 Has 版本(Missing HasSharedFragment 等)未实现。行为即所转发的新函数(转发前校验类型派生与记警告)。DeprecationMessage 统一指向节点显示名而非函数名:HasMassTag / AddMassTag / RemoveMassTag、HasMassFragment / GetMassFragment / SetMassFragment / RemoveMassFragment、HasMassFlag / SetMassFlag / ClearMassFlag。
A batch of legacy APIs at the file tail, flagged Category = "MassAPI|ZDeprecated" + DeprecatedFunction (with (Deprecated) DisplayNames and DeprecationMessages), all forwarding to the new names: Tag sextet (HasTag / AddTag / RemoveTag / HasTag_TemplateData / AddTag_TemplateData / RemoveTag_TemplateData), Fragment septet (HasFragment / RemoveFragment / GetFragment / SetFragment / HasFragment_TemplateData / RemoveFragmentInTemplate / GetFragmentFromTemplate / SetFragmentInTemplate), SharedFragment quintet (RemoveSharedFragment / GetSharedFragment / SetSharedFragment / RemoveSharedFragmentInTemplate / SetSharedFragmentInTemplate), ConstSharedFragment quintet (RemoveConstSharedFragment / GetConstSharedFragment / SetConstSharedFragment / RemoveConstSharedFragmentInTemplate / SetConstSharedFragmentInTemplate), Flag sextet (HasEntityFlag / ClearEntityFlag / SetEntityFlag / HasTemplateFlag / ClearTemplateFlag / SetTemplateFlag). Has variants marked "Missing" in source comments are not implemented. Behavior is that of the forwarded new functions (with pre-forward type checks and warnings). The DeprecationMessages point at unified node display names rather than function names: HasMassTag / AddMassTag / RemoveMassTag, HasMassFragment / GetMassFragment / SetMassFragment / RemoveMassFragment, and HasMassFlag / SetMassFlag / ClearMassFlag.
管线角色 Pipeline Role
蓝图函数库,无自身 tick,仅被蓝图节点与 K2 节点调用。ForEach 游标函数(BeginEntityForEach / AdvanceEntityForEach / BeginEntityHandleArrayForEach / AdvanceEntityHandleArrayForEach)被 ForEachMatchingEntities 与 ForEachEntityHandle K2 节点(MassAPIUncooked 模块)内部调用,游标状态存于 UMassAPISubsystem。所有实体操作经 UMassAPISubsystem::GetPtr(WorldContext) 路由到子系统;延迟操作写入子系统的 SharedCommandBuffer,由子系统每 tick 刷新。
A Blueprint function library with no tick of its own; called only from Blueprint nodes and K2 nodes. The ForEach cursor functions (BeginEntityForEach / AdvanceEntityForEach / BeginEntityHandleArrayForEach / AdvanceEntityHandleArrayForEach) are called internally by the ForEachMatchingEntities and ForEachEntityHandle K2 nodes (MassAPIUncooked module), with cursor state stored on UMassAPISubsystem. All entity operations route through UMassAPISubsystem::GetPtr(WorldContext); deferred operations write into the subsystem's SharedCommandBuffer, flushed by the subsystem every tick.