tag-component
Mark entity membership in a logical group or boolean state without storing any data, enabling query-level dispatch with zero chunk overhead.
- License 许可
- MIT
- 最近更新
- 2026-07-25
- Stars
- ★ 8
- Forks
- 0
01 前言 Front Matter
- name
- tag-component
- tags
- [ "core", "components" ]
- metadata
- { "tier": 3, "internal-only": true }
- description
- Mark entity membership in a logical group or boolean state without storing any data, enabling query-level dispatch with zero chunk overhead.
03 SKILL.md 正文
Tag Component
Intent
Mark entity membership in a logical group or boolean state without storing any data, enabling query-level dispatch with zero chunk overhead.
Use When
Boolean, infrequently-changing state that drives which systems include or exclude an entity. Scene activation, feature flags, event signals, state labels.
Avoid When
The state changes every frame or many times per second — structural change cost is non-trivial at high frequency. Use IEnableableComponent instead.
Senior Pattern
- Empty struct implementing IComponentData.
- Add/remove via ECB, never during iteration.
- Use RequireForUpdate<T> to gate systems on tag presence.
- Use WithAll<T>/WithNone<T> in queries to filter on tag.
Code Template
public struct IsActiveEnemy : IComponentData { }
// Gate a system on tag existence:
state.RequireForUpdate<IsActiveEnemy>();
// Filter query — only entities that have IsActiveEnemy:
foreach (var transform in
SystemAPI.Query<RefRW<LocalTransform>>().WithAll<IsActiveEnemy>())
{ }
// Add via ECB (safe from job):
ecb.AddComponent<IsActiveEnemy>(entity);
Anti-Patterns
- Adding and removing a tag every frame on many entities — causes per-frame archetype migrations and chunk allocations.
- Using a tag where the actual state needs a value — unnecessary structural change when a field on an existing component would do.
- Checking tag presence via EntityManager.HasComponent in a per-entity loop — use query filters instead.
Runtime Risks
- High-frequency add/remove of tags on large entity populations: archetype churn, chunk fragmentation, GC pressure from chunk reallocation.
Performance Notes
- Zero bytes in chunk. Adding the tag moves the entity to a different archetype chunk — one-time cost per transition.
- Query filter on tag presence is O(archetypes), not O(entities).
Architecture Guidance
Tags represent stable states with infrequent transitions. Design entity lifecycles around a small number of meaningful archetype states, not a high-churn tag soup.
04 同仓库更多 Skills
dots-update-groups
How to choose the right ECS system group and ordering so per-frame and per-fixed-step work is deterministic and never races its own readers. Covers InitializationSystemGroup / SimulationSystemGroup / PresentationSystemGroup / FixedStepSimulationSystemGroup / VariableRateSimulationSystemGroup, UpdateBefore / UpdateAfter peer ordering, OrderFirst / OrderLast group-boundary placement, RateManager, and the cross-group ordering trap. Use when adding an ISystem, fixing "value visible one frame late" bugs, or coupling simulation to a fixed timestep.
dots-transform-patterns
The Entities 1.x transform model — LocalTransform (writable input) vs LocalToWorld (system-owned matrix), Parent/Child hierarchy, reparenting cost, uniform vs non-uniform scale (PostTransformMatrix), and when to opt out with custom transform systems. Use when designing parent/child hierarchies, runtime reparenting (mount/dismount/socket), or choosing transform components at the Baker boundary.
dots-singleton-patterns
Model cross-system shared configuration and game state as a single-entity component with a strict single-writer contract. Covers RequireForUpdate gating, SystemAPI.GetSingleton / GetSingletonRW / HasSingleton / TryGetSingleton, bake-time vs runtime-created vs ECB-system singletons, the "exactly one entity" runtime invariant, and the single-writer rule. Use when designing frame-stable global config, shared mutable state, or any component intended to exist on exactly one entity.
dots-hybrid-bridge
The one-way bridge between DOTS-owned runtime state and Unity-owned presentation. Covers UnityObjectRef for managed asset refs in components, the DOTS-writes / Unity-reads ownership rule, when to use managed IComponentData vs UnityObjectRef vs CompanionComponent, baker-bridge vs runtime-bridge, and SubScene boundary rules. Use when an entity must reference Unity assets (Mesh, Material, AudioClip, ScriptableObject), a MonoBehaviour view must read entity state, or input/UI must trigger ECS work.
dots-event-driven-ecs
Model one-frame events and external requests in ECS without dual ownership, polling, or persistent state leaks. Covers request-tag pattern with ECB, enableable command components (no structural change), event buffers (IBufferElementData), explicit consumer ownership, one-frame latency rules, and the banned C# event / UnityEvent / static bus anti-patterns. Use when input/UI/network must trigger ECS work, when a one-frame signal fans out to N consumers (damage, hit, collision), or when state changes must be processed exactly once.
valid_skill
A complete, well-formed test fixture skill for SkillHub validation testing. Covers basic task routing and code review for Unity projects.