wave4-ijobentity-advanced-patterns
Extend IJobEntity with query filters, sort key parameters, and implicit-query scheduling for production ECS systems.
- License 许可
- MIT
- 最近更新
- 2026-07-25
- Stars
- ★ 8
- Forks
- 0
01 前言 Front Matter
- name
- wave4-ijobentity-advanced-patterns
- tags
- [ "jobs", "query" ]
- metadata
- { "tier": 3, "internal-only": true }
- description
- Extend IJobEntity with query filters, sort key parameters, and implicit-query scheduling for production ECS systems.
03 SKILL.md 正文
IJobEntity — Advanced Patterns
Intent
Extend IJobEntity with query filters, sort key parameters, and implicit-query scheduling for production ECS systems.
Use When
- Structural component filters needed:
[WithAll],[WithNone],[WithAny],[WithDisabled],[WithPresent]. - ECB.ParallelWriter used and deterministic sort key required (
[ChunkIndexInQuery]). - Per-entity NativeArray writes need a stable index (
[EntityIndexInQuery]).
Avoid When
Per-chunk metadata (unfilteredChunkIndex, DidChange, SharedComponent values) required — use IJobChunk.
Senior Pattern
[WithAll(typeof(ActiveTag))]
[WithNone(typeof(DeadTag))]
[WithDisabled(typeof(FrozenTag))]
[BurstCompile]
public partial struct MoveJob : IJobEntity
{
public EntityCommandBuffer.ParallelWriter Ecb;
public float DeltaTime;
[BurstCompile]
public void Execute(
[ChunkIndexInQuery] int chunkIndex,
Entity entity,
ref LocalTransform transform,
in Velocity velocity)
{
transform.Position += velocity.Value * DeltaTime;
if (transform.Position.y < -100f)
Ecb.DestroyEntity(chunkIndex, entity);
}
}
state.Dependency = new MoveJob
{
Ecb = ecbSys.CreateCommandBuffer().AsParallelWriter(),
DeltaTime = SystemAPI.Time.DeltaTime
}.ScheduleParallel(state.Dependency);
Parameter Semantics
ref T— read/write (RW type handle).in T— read-only (RO type handle; allows parallel reads with other RO jobs).[ChunkIndexInQuery] int— chunk-level sort key for ECB.ParallelWriter; unique per chunk, deterministic.[EntityIndexInQuery] int— entity-level index within query; use as NativeArray write index for scatter patterns.Entity entity— required when using ECB commands on the current entity.
Anti-Patterns
- Using
[ChunkIndexInQuery]as NativeArray write index — chunk-level, not entity-level; multiple entities in same chunk write same slot. - Using
[EntityIndexInQuery]as ECB.ParallelWriter sort key — not chunk-stable; use[ChunkIndexInQuery]instead. - Forgetting
partialon the struct — source generation silently fails. - Not assigning result to
state.Dependencywhen work should persist across system boundaries.
Runtime Risks
- Wrong sort key for ECB.ParallelWriter = non-deterministic structural change order across frames.
- Missing
[WithNone]for intended exclusion filters — queries silently match more entities than expected.
Architecture Guidance
Default job type for ECS simulation work. Use [WithAll]/[WithNone] attributes on the struct to keep query intent co-located with the job. Reserve IJobChunk for cases where per-chunk metadata is genuinely required.
Related Skills
[[ijobentity-parallel-job]], [[ijobchunk-full-anatomy]], [[ecb-parallel-writer]], [[entity-index-in-query-scatter-pattern]]
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.