What problem does it solve?
ecs-job-patterns helps prevent common DOTS/ECS threading and scheduling mistakes by standardizing how Unity jobs use dependencies, avoid sync points, and perform structural changes safely.
Core Features & Use Cases
- Job scheduling with dependency discipline: Reads
state.Dependency before scheduling, writes the resulting JobHandle back to state.Dependency, and avoids unsafe .Complete() calls inside OnUpdate.
- Structural changes via ECB: Performs
AddComponent/RemoveComponent/entity creation-destruction using EntityCommandBuffer.ParallelWriter rather than calling EntityManager from jobs, with correct playback group selection.
- Correct component access patterns: Uses
ComponentLookup<T> for random component access in jobs (including updating it each OnUpdate), and uses SystemAPI.Query / SystemAPI.GetSingleton for the appropriate access type.
- Update-order guardrails: Flags architecture risk when changing
UpdateBefore/UpdateAfter/UpdateInGroup without approved plan constraints.
Quick Start
Ask the agent to implement an ECS job that schedules from state.Dependency, uses EntityCommandBuffer.ParallelWriter for structural changes, and updates ComponentLookup at the start of OnUpdate.