entity-query-patterns-systemapi-query

Applies SystemAPI.Query with RefRO/RefRW access intent for Unity DOTS main-thread iteration.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps developers avoid silent “system runs but nothing changes” bugs and performance bottlenecks by teaching the correct main-thread iteration pattern for Unity DOTS using SystemAPI.Query and strict RefRO/RefRW access intent.

Core Features & Use Cases

  • RefRO/RefRW intent discipline: Use RefRO for read-only components and RefRW only for values you genuinely write, so the loop expresses correct access and avoids scheduling/parallelism issues.
  • Refined query filtering: Apply composable filters like WithAll, WithNone, WithAny, WithEntityAccess, and enableable-component options to precisely target the intended archetypes.
  • Safety against structural-change traps: Prevent invalid iterators and skipped/duplicated entities by avoiding EntityManager structural mutations inside the foreach and using an ECB-based approach instead.
  • Promotion guidance: Know when to stay on SystemAPI.Query versus when to move to IJobEntity for large entity counts or heavier per-entity work.

Quick Start

Ask an AI to review your ISystem OnUpdate and explain whether your SystemAPI.Query tuple correctly uses RefRO vs RefRW and whether you’re risking structural changes inside the foreach.

Frequently Asked Questions about entity-query-patterns-systemapi-query

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

FAQPage Schema
Why does my Unity DOTS system run but nothing changes during entity iteration?

Your Unity DOTS system runs but nothing changes likely because SystemAPI.Query lacks correct RefRO/RefRW access intent. Using RefRW for read-only components or RefRO for writes causes silent scheduling conflicts, preventing the main-thread foreach loop from properly executing archetype-chunk iteration.

How do I use SystemAPI.Query with RefRO and RefRW correctly in ISystem.OnUpdate?

To use SystemAPI.Query correctly in ISystem.OnUpdate, apply RefRO strictly for read-only components and RefRW only for values you genuinely write. This access intent discipline ensures proper type-level read/write safety and avoids parallelism issues during main-thread archetype-chunk iteration.

Can I make structural changes to entities inside a SystemAPI.Query foreach loop?

You cannot safely make structural changes inside a SystemAPI.Query foreach loop. Using EntityManager mutators directly causes invalid iterators and skipped or duplicated entities. Use an EntityCommandBuffer (ECB) based approach instead to safely defer structural changes during archetype-chunk iteration.

How do I filter archetypes with WithAll, WithNone, and WithAny in SystemAPI.Query?

You filter archetypes in SystemAPI.Query by applying composable filters like WithAll, WithNone, and WithAny. These refinements precisely target intended archetypes during entity iteration, ensuring your ISystem.OnUpdate loop processes only the specific components matching your query criteria.

When should I move from SystemAPI.Query to IJobEntity in Unity DOTS?

You should move from SystemAPI.Query to IJobEntity when scale or per-entity workload increases significantly. If your main-thread archetype-chunk iteration handles large entity counts or heavier computations, promoting the loop to IJobEntity satisfies performance requirements and enables parallel scheduling.

What is RefRW intent discipline in Unity DOTS ECS iteration?

RefRW intent discipline in Unity DOTS ECS iteration means using RefRW exclusively for component values you genuinely write inside the SystemAPI.Query loop. This strict type-level read/write discipline prevents scheduling conflicts and ensures your main-thread system correctly expresses its access intent.