# Bevy Ecs Composition

Compose Bevy 0.20 entities from small components and systems.

- Repository: https://github.com/thedivergentai/Game-Dev-Agentic-Skills (917 stars)
- Category: Engineering
- License: LGPL-3.0
- Last updated: 2026-10-16
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-ecs-composition -g -a claude-code -y`
Codex: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-ecs-composition -g -a codex -y`
Cursor: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-ecs-composition -g -a cursor -y`
Gemini CLI: `npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-ecs-composition -g -a gemini-cli -y`

## Description

Compose Bevy 0.20 entities from small components and systems. Use when spawning tuples with Commands, filtering Query with With, ordering writers with chain, or attaching ChildOf. Keywords: Bevy, ECS, Component, Query, Commands, chain, ChildOf.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Bevy ECS composition

## When to use

Load this when gameplay data should be split across small components and systems, instead of one type that owns everything. The Quick Start ECS page is the source for the names below.

## ECS shape

- **Components** are Rust structs that derive `Component`. The ECS page splits `Person` and `Name` so more than one kind of entity can carry a name.
- **Entities** are spawned with `Commands` in a `Startup` system. The page spawns a tuple of components: `commands.spawn((Person, Name(...)))`.
- **Systems** are functions. `Query<&Name, With<Person>>` reads names on entities that also have `Person`. `Query<&mut Name, With<Person>>` writes. Register with `add_systems`.
- **Schedule:** `Startup` runs once. `Update` runs afterward. Systems run in parallel unless you call `.chain()`. The page chains `update_people` before `greet_people` and leaves an unrelated system outside the chain.

Spawn a tuple of components. A parent and child use `ChildOf`. Change detection uses `Changed`.

## Composition choices

| Need | Bevy idiom |
| --- | --- |
| Has-a parts on one object | Several `Component` structs on one entity |
| Behavior | A system function over a `Query` |
| Spawn at start | `Commands` in a `Startup` system |
| Ordered steps | `.chain()` on the systems that depend on each other |
| Parent and child | `ChildOf` on the child entity |

## Scope

- Tuple spawn, `ChildOf`, `Changed`, and `.chain()` are in the examples below.
- Editor widget trees are out of scope. Composition here is entities, components, and systems.

```toml
[package]
name = "ecs-composition"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.20"
```

People carry a name. Greeting runs after the rename, in one chain.

```rust
#[derive(Component)]
struct Person;

#[derive(Component)]
struct Name(String);

fn spawn_people(mut commands: Commands) {
    commands.spawn((Person, Name("Ada".to_string())));
    commands.spawn(Name("crate".to_string()));
}

The rest: https://github.com/thedivergentai/Game-Dev-Agentic-Skills/blob/HEAD/skills/bevy-ecs-composition/SKILL.md
