batch-structural-change-on-query

Apply structural changes to all entities matched by an EntityQuery.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It avoids slow, error-prone per-entity loops by enabling structural changes across all entities that match an ECS query in a single operation, reducing archetype thrash and eliminating iterator invalidation risks.

Core Features & Use Cases

  • One-pass structural changes: Perform operations like destroy, add, remove, or enable/disable components across all entities selected by an EntityQuery without iterating entities individually.
  • Performance-focused query usage: Apply query-level APIs for uniform changes where every matching entity should receive the same outcome.
  • Safer ECS patterns: Help prevent runtime exceptions by avoiding query-overload structural changes inside active SystemAPI.Query foreach loops.

Real-world use case: cleaning up scene entities by destroying a set of matched enemies and removing a “wave complete” component from all remaining wave entities in one frame.

Quick Start

Ask the AI to rewrite your ECS system so it uses state.EntityManager.<Action>(m_Query) with a cached EntityQuery built once during OnCreate, rather than looping over entities and calling per-entity structural methods.

Frequently Asked Questions about batch-structural-change-on-query

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

FAQPage Schema
How do I perform structural changes on all entities matching an ECS query at once?

To perform structural changes on all entities matching an ECS query, apply EntityManager query-overload APIs using a cached EntityQuery instead of iterating entities individually. This enables single-pass operations like destroying matched entities or adding components safely.

Why does iterating entities individually for structural changes cause errors in Unity DOTS?

Iterating entities individually for structural changes causes errors because per-entity loops risk iterator invalidation during active SystemAPI.Query iteration. Using query-overload APIs avoids this by applying uniform changes in a single operation.

What's the best way to destroy multiple entities in a single frame using EntityManager?

The best way to destroy multiple entities in a single frame is building and caching an EntityQuery during OnCreate, then invoking the single-pass destroy operation with that query to eliminate archetype thrash and runtime exceptions.

Can I add or remove components from multiple entities without a foreach loop in Unity ECS?

Yes, you can add or remove components from multiple entities without a foreach loop by invoking query-level EntityManager APIs on a cached EntityQuery, applying uniform structural changes across all matched entities in one pass.

What happens if I trigger structural changes inside an active SystemAPI.Query foreach loop?

Triggering structural changes inside an active SystemAPI.Query foreach loop causes iterator invalidation risks and runtime exceptions. You must avoid query-overload structural changes during iteration and apply them as separate single-pass operations.

When do I need batch structural changes for entity management in Unity DOTS?

You need batch structural changes for entity management when performing mass operations like destroying matched enemies or toggling component enabled states across uniformly affected query results, requiring a cached EntityQuery to execute safely and fast.