transform-usage-flags
Declare exactly which transform components an entity needs at bake time, preventing spurious LocalTransform/LocalToWorld components on data-only entities and missing transforms on moving entities.
- License 许可
- MIT
- 最近更新
- 2026-07-25
- Stars
- ★ 8
- Forks
- 0
01 前言 Front Matter
- name
- transform-usage-flags
- tags
- [ "baking", "transforms" ]
- metadata
- { "tier": 3, "internal-only": true }
- description
- Declare exactly which transform components an entity needs at bake time, preventing spurious LocalTransform/LocalToWorld components on data-only entities and missing transforms on moving entities.
03 SKILL.md 正文
TransformUsageFlags
Intent
Declare exactly which transform components an entity needs at bake time, preventing spurious LocalTransform/LocalToWorld components on data-only entities and missing transforms on moving entities.
Use When
Every call to GetEntity() and CreateAdditionalEntity() in a Baker. The flag must match the entity's actual runtime behavior.
Avoid When
There is no "avoid when" — TransformUsageFlags must always be specified explicitly. Never guess; derive the flag from how the entity will be used at runtime.
Senior Pattern
TransformUsageFlags.None— data-only entities (config, singletons, tags, staging entities). No LocalTransform added.TransformUsageFlags.Dynamic— entities that move at runtime. Adds LocalTransform + LocalToWorld.TransformUsageFlags.Renderable— entities rendered but not moved by ECS systems (static mesh renderers). Adds LocalToWorld only.TransformUsageFlags.ManualOverride— Baker takes full responsibility for adding transform components. Used when batch-adding many components via ComponentTypeSet to minimize archetype migrations.- For prefab entity references:
GetEntity(authoring.PrefabField, TransformUsageFlags.Dynamic).
Code Template
class Baker : Baker<EnemyAuthoring>
{
public override void Bake(EnemyAuthoring authoring)
{
// Moving enemy — needs LocalTransform
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new EnemyData { Speed = authoring.Speed });
// Config singleton — no transform needed
var configEntity = CreateAdditionalEntity(TransformUsageFlags.None);
AddComponent(configEntity, new EnemyConfig { MaxCount = authoring.MaxCount });
// Batch add via ManualOverride — single structural change
var tileEntity = CreateAdditionalEntity(TransformUsageFlags.ManualOverride);
AddComponent(tileEntity, new ComponentTypeSet(
ComponentType.ReadWrite<LocalTransform>(),
ComponentType.ReadWrite<LocalToWorld>(),
ComponentType.ReadWrite<TileData>()
));
SetComponent(tileEntity, LocalTransform.FromPosition(authoring.TileOffset));
}
}
Anti-Patterns
- Using
TransformUsageFlags.Dynamicon a static/data-only entity — wastes chunk space, triggers unnecessary TransformSystemGroup processing every frame. - Using
TransformUsageFlags.Noneon an entity that moves — LocalTransform is absent at runtime, transform system skips it, entity never moves. - Using
TransformUsageFlags.ManualOverrideand forgetting to AddComponent the transform manually — silently broken transforms, no compile or runtime error until movement is attempted.
Runtime Risks
- Wrong flag = wrong archetype = wrong system behavior. Static entities with Dynamic flag waste memory and CPU. Moving entities with None flag are invisible to the transform system.
Performance Notes
- None = smallest archetype footprint. Prefer for all config/singleton entities.
- ManualOverride + ComponentTypeSet batch add = single structural change for all components, minimum archetype migrations during baking.
Architecture Guidance
Match the flag to how the runtime system will use the entity. If unsure, check which systems query for LocalTransform — if your entity needs to be in those queries, use Dynamic.
Related Skills
[[baker-authoring-conversion]]
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.