AGENT SKILL

unity-dots-best-practices

Unity DOTS, ECS, Jobs, and Burst guidance for scalable runtime systems. Core best-practices covering components, systems, bakers, blob assets, scheduling, structural change costs, and performance-sensitive simulation patterns for Entities 1.3+.

License 许可
MIT
最近更新
2026-07-25
Stars
★ 8
Forks
0

01 前言 Front Matter

name
unity-dots-best-practices
metadata
{ "tier": 1, "source": "https://docs.unity3d.com/Packages/com.unity.entities@1.3", "version": "1.3.8", "user-invocable": false }
use-when
Load for unity-dots-dev on any DOTS or Hybrid domain task. Always included as P1 knowledge for architect and unity-dots-dev. Load when writing ISystem, IJobEntity, Baker, blob assets, ECB, or any ECS architecture decisions.
platforms
[ "claude-code", "codex", "copilot", "cursor", "windsurf" ]
description
Unity DOTS, ECS, Jobs, and Burst guidance for scalable runtime systems. Core best-practices covering components, systems, bakers, blob assets, scheduling, structural change costs, and performance-sensitive simulation patterns for Entities 1.3+.
do-not-use-when
Do not load for the unity-dev classic lane (MonoBehaviour tasks). Do not load for tester or verifier roles. Not needed for pure editor-tooling with no runtime ECS.
task-categories
[ "ecs", "performance", "burst", "jobs", "dots" ]

03 SKILL.md 正文

Unity DOTS Best Practices

When working on Unity DOTS runtime code, design and verify against these constraints. See @.claude/docs/mcp-integration.md for ai-game-developer and agentmemory tool usage.

Design Principles

  • Design around data layout and access patterns first.
  • Prefer IComponentData, IBufferElementData, BlobAssetReference<T>, IAspect, ISystem, Burst, and jobs where they clearly improve scale and maintainability.
  • Keep hot paths allocation-free — no managed objects in simulation code.
  • Minimize structural changes inside frequently executed loops.
  • Treat archetype churn, sync points, and main-thread fallbacks as explicit costs, not background noise.
  • Keep authoring/baker code separate from runtime systems (asmdef boundaries).
  • Make update order and ownership explicit. Never imply ordering.
  • Prefer deterministic, debuggable data flow over implicit side effects.

Component & Buffer Design

  • One concern per component. Don't pack unrelated fields just because they share an entity.
  • IBufferElementData for variable-size per-entity data; cap with InternalBufferCapacity thoughtfully.
  • BlobAssetReference<T> for large, immutable, shared data (e.g., level configs, ability data).
  • IEnableableComponent for state toggles that would otherwise cause add/remove churn.
  • Avoid managed components except for editor-bridging cases.

System Design

  • Prefer ISystem (Burst-compilable) over SystemBase for hot paths.
  • Use SystemAPI for queries, singletons, time, lookups — keeps intent explicit.
  • Explicit [UpdateInGroup], [UpdateAfter], [UpdateBefore] — never rely on implicit ordering.
  • Keep system responsibilities narrow. Compose, don't merge.

Job Design

  • IJobEntity for per-entity work where chunk access is not needed.
  • IJobChunk when you need chunk-level batching, change filtering, or component lookup optimization.
  • EntityCommandBuffer for structural changes, with intentional playback point.
  • EntityCommandBuffer.ParallelWriter for parallel structural changes — pass sortKey correctly.
  • Manage Dependency explicitly when chaining multiple jobs.

Burst Compatibility

  • No managed references, no virtual dispatch, no string, no throw in hot loops.
  • BurstCompile everything that can be Burst-compiled. Address compilation failures immediately.
  • [BurstCompile(CompileSynchronously = true)] for tests so failures surface in CI.

NativeContainers

  • Allocator choice: Allocator.Temp (single frame, main thread), Allocator.TempJob (≤4 frames), Allocator.Persistent (long-lived).
  • Always dispose. Use using or explicit .Dispose() in OnDestroy.
  • Pass [ReadOnly] and [WriteOnly] attributes to enable parallelism.

Self-Check Before Finalizing

  1. Is the data representation aligned with read/write patterns?
  2. Are there avoidable sync points? (EntityManager.CompleteAllTrackedJobs, .GetSingleton, structural changes outside ECB)
  3. Are structural changes limited and intentional?
  4. Is this Burst/job friendly? Any non-Burst-compatible types?
  5. Will the approach scale to large entity counts (target: 10k–100k)?
  6. Have I memoized any per-frame allocations into job-owned containers?
  7. Have I confirmed Unity-side state with mcp__ai-game-developer__gameobject-component-get (for authoring) or tests-run (for behavior)?
  8. Have I saved a memory_lesson_save for non-obvious decisions?

Anti-Patterns

  • EntityManager.CreateEntity / AddComponent inside OnUpdate without ECB
  • Capturing managed lambdas in SystemBase.Entities.ForEach hot paths
  • Using SystemBase where ISystem would work
  • Implicit system ordering ("it happens to run before X")
  • Buffers used as unbounded queues without consume logic
  • One giant component that everyone reads and writes
  • Manager-pattern singletons disguised as ECS singletons

04 同仓库更多 Skills

dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

律师与法务
★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

valid_skill

A complete, well-formed test fixture skill for SkillHub validation testing. Covers basic task routing and code review for Unity projects.

代码审查测试与质量
★ 8