ECS Query Patterns

Build zero-allocation Arch ECS queries for Godot 4.x systems.

2|Updated Jul 2, 2026
One-click install
npx skills add https://github.com/Xyrces/godot-ecs-gamedev-playbook --skill ecs-query-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ECS Query Patterns
Source: https://github.com/Xyrces/godot-ecs-gamedev-playbook/tree/main/skills/ecs_query_patterns
Command: npx skills add https://github.com/Xyrces/godot-ecs-gamedev-playbook --skill ecs-query-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you find and process the right entities in an ECS without wasting frame time on allocations, repeated query setup, or inefficient per-entity checks.

Core Features & Use Cases

  • Query Filtering: Build precise entity matches with WithAll, WithAny, WithNone, and stricter archetype rules.
  • Hot-Path Iteration: Use struct-based handlers and ref iteration to keep gameplay systems allocation-free.
  • Reusable Queries: Cache QueryDescription instances for combat, movement, AI, and other per-frame systems.
  • Bulk and Relationship Operations: Count, collect, add, remove, and update components across matching entities, including parent-child style relationships.
  • Use Case: A Godot 4.x action game can use this Skill to update all enemies, apply damage only to valid targets, and keep simulation code deterministic and fast.

Quick Start

Use this skill to design an efficient Arch ECS query for the entities and components you need, then cache it and iterate with a zero-allocation handler.

Frequently Asked Questions about ECS Query Patterns

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

FAQPage Schema
How do I write zero-allocation ECS queries in Godot 4.x?

Cache QueryDescription instances and iterate them using struct-based handlers with ref iteration to process matching entities without allocating memory during the Godot 4.x game loop.

What is the best way to filter entities in Arch ECS for combat and AI logic?

The best way to filter entities in Arch ECS is using QueryDescription with WithAll, WithAny, and WithNone rules. This builds precise archetype matches for combat, AI, and movement systems without per-entity checks.

Why does my ECS query allocate memory every frame in Godot?

Your ECS query allocates memory every frame if QueryDescription instances are rebuilt repeatedly or if non-struct handlers are used. Cache queries and use struct-based ref iteration to keep gameplay systems allocation-free.

Can I cache Arch ECS queries for per-frame gameplay systems?

Yes, you can cache QueryDescription instances in Arch ECS for per-frame gameplay systems. Reusable cached queries allow combat, movement, and AI logic to run efficiently without repeated query setup overhead.

How do I perform bulk component updates on matching entities in an ECS?

Perform bulk component updates on matching entities by building a QueryDescription filter and iterating the results with a struct handler. This lets you add, remove, or update components across all matching entities efficiently.

Does Arch ECS support parent-child relationship traversal in Godot?

Arch ECS supports parent-child style relationship traversal in Godot 4.x. You can build queries that find and process matching entities based on their relationship components without allocation overhead.