wave4-entity-index-in-query-scatter-pattern

Scatter per-entity IJobEntity outputs into a pre-allocated NativeArray using EntityIndexInQuery indices.

6|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/dyCuong03/unity-agent-team --skill wave4-entity-index-in-query-scatter-pattern
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: wave4-entity-index-in-query-scatter-pattern
Source: https://github.com/dyCuong03/unity-agent-team/tree/main/.claude/skills/unity-dots/wave4-entity-index-in-query-scatter-pattern
Command: npx skills add https://github.com/dyCuong03/unity-agent-team --skill wave4-entity-index-in-query-scatter-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the challenge of safely writing per-entity computed results into a shared NativeArray from a parallel Entities job without collisions or locks.

Core Features & Use Cases

  • Stable per-entity indexing: Uses [EntityIndexInQuery] so each entity writes to its own pre-allocated array slot.
  • Lock-free parallel scatter → downstream gather: Supports a two-phase workflow where scatter runs in parallel and a later phase consumes the results.
  • Capacity correctness: Emphasizes sizing the array from query.CalculateEntityCount() to prevent out-of-bounds writes in Burst.

Use it when you have a parallel IJobEntity that must produce a result per entity for an inter-job pipeline (for example, computing and storing positions/derived data for a later job that reads them).

Quick Start

Use the [EntityIndexInQuery] index in a Burst-compiled IJobEntity to scatter into a NativeArray sized from query.CalculateEntityCount() for a downstream gather phase.

Frequently Asked Questions about wave4-entity-index-in-query-scatter-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely write per-entity results into a NativeArray from a parallel Unity DOTS job?▼

To safely write per-entity results into a NativeArray from a parallel Unity DOTS job, use the [EntityIndexInQuery] attribute to assign each entity a unique, stable index for writing to its own pre-allocated array slot without locks.

What is the best way to pass data between parallel IJobEntity jobs in Unity DOTS?▼

The best way to pass data between parallel IJobEntity jobs is a lock-free scatter-gather pattern, where the first job computes results into a shared NativeArray and a downstream job consumes them sequentially.

Why does my parallel Entities.ForEach job cause out-of-bounds errors when scattering to a NativeArray?▼

Out-of-bounds errors during NativeArray scatter occur when the array capacity is not sized exactly to query.CalculateEntityCount(), causing parallel writers to exceed the allocated memory under Burst compilation.

Does writing to a shared NativeArray in a parallel IJobEntity require locking or atomics?▼

Writing to a shared NativeArray in a parallel IJobEntity does not require locking or atomics if you use [EntityIndexInQuery] to guarantee each entity writes to a unique, stable array slot.

When do I need to use EntityIndexInQuery for scatter-gather workflows in Unity?▼

You need to use EntityIndexInQuery for scatter-gather workflows when a parallel IJobEntity must produce per-entity computed results into a pre-allocated NativeArray for a downstream job to consume lock-free.

What are the limitations of using EntityIndexInQuery to scatter results in a NativeArray?▼

Limitations of using EntityIndexInQuery include the strict requirement for a unique entity-to-index mapping and accurate NativeArray sizing via CalculateEntityCount, as any mismatch causes out-of-bounds writes under Burst.