Skip to content

77 game-dev skills for AI coding agents — Godot, Unity, Unreal, Phaser, PixiJS, three.js, Bevy, pygame, LÖVE, Roblox. Portable SKILL.md Agent Skills (the format Anthropic launched as Claude Skills), with a router that loads the right skill for your engine and task. Runs in Claude Code, Cursor, Kiro, Codex, Copilot, Gemini CLI and more.

feat(bevy-ecs): update to Bevy 0.20

Abhishek Baralia3cd800a846f
diff --git a/docs/VERSION-SUPPORT.md b/docs/VERSION-SUPPORT.md
index 457a415..6a681da 100644
--- a/docs/VERSION-SUPPORT.md
+++ b/docs/VERSION-SUPPORT.md
@@ -1,6 +1,7 @@
# Version support
-Checked **2026-09-25**. These are authoring baselines for **new projects**, not forced upgrade
+Checked **2026-09-25** (Bevy row re-checked **2026-10-09** for the 0.20 release). These are
+authoring baselines for **new projects**, not forced upgrade
targets. Existing projects keep the version declared by their manifest, lockfile, or engine
metadata unless the user explicitly asks for migration.
@@ -13,7 +14,7 @@ metadata unless the user explicitly asks for migration.
| Phaser | 4.2 | `package.json` + lockfile; [Phaser downloads](https://phaser.io/download/phaser4) and [3→4 migration](https://phaser.io/news/2026/04/migrating-from-phaser-3-to-phaser-4-what-you-need-to-know) |
| PixiJS | 8.21 | `package.json` + lockfile; [PixiJS releases](https://pixijs.com/blog) |
| three.js | r186 | `package.json` + lockfile; [three.js releases](https://github.com/mrdoob/three.js/releases) |
-| Bevy | 0.19 | `Cargo.toml` + `Cargo.lock`; [Bevy 0.19](https://bevy.org/news/bevy-0-19/) and [migration guide](https://bevy.org/learn/migration-guides/0-18-to-0-19/) |
+| Bevy | 0.20 | `Cargo.toml` + `Cargo.lock`; [Bevy 0.20](https://bevy.org/news/bevy-0-20/) and [migration guide](https://bevy.org/learn/migration-guides/0-19-to-0-20/) |
| pygame-ce | 2.5.8 | Python dependency/lockfile; [pygame-ce releases](https://github.com/pygame-community/pygame-ce/releases) |
| LÖVE | 11.5 | `conf.lua` / `main.lua`; [LÖVE releases](https://love2d.org/wiki/Version_History) |
| Roblox | rolling platform APIs | Rojo project / place files; [Creator Hub](https://create.roblox.com/docs) |
diff --git a/skills/other-engines/README.md b/skills/other-engines/README.md
index 266e0e3..a2d1f9f 100644
--- a/skills/other-engines/README.md
+++ b/skills/other-engines/README.md
@@ -1,6 +1,6 @@
# Other engine skills
-Ten Agent Skills for Bevy 0.19, pygame-ce 2.5.8, LÖVE 11.5, and Roblox. Roblox coverage includes
+Ten Agent Skills for Bevy 0.20, pygame-ce 2.5.8, LÖVE 11.5, and Roblox. Roblox coverage includes
Luau, persistence, UI, networking, characters, physics, and Studio workflow.
Each subdirectory is one skill. Existing projects keep their pinned engine or
diff --git a/skills/other-engines/bevy-ecs/SKILL.md b/skills/other-engines/bevy-ecs/SKILL.md
index 1aecec6..be816d0 100644
--- a/skills/other-engines/bevy-ecs/SKILL.md
+++ b/skills/other-engines/bevy-ecs/SKILL.md
@@ -13,7 +13,7 @@ description: >
Structure a Bevy game in Rust around the Entity Component System: the `App` and
plugins, components and resources, systems with queries, scheduling, and
-frame-rate-independent updates. New examples target **Bevy 0.19**. If the project
+frame-rate-independent updates. New examples target **Bevy 0.20**. If the project
already pins another release, keep that release and use its matching migration guide.
## When to use
@@ -31,14 +31,15 @@ procedural algorithms, pair with `game-ai` / `procedural-gen`.
## Core workflow
1. **Detect and pin the version.** Read `Cargo.toml` and `Cargo.lock` first. For a
- new project use `bevy = "0.19"`; never silently migrate an existing project
+ new project use `bevy = "0.20"`; never silently migrate an existing project
across a Bevy minor release. Treat the matching docs and migration guides as truth.
2. **Build the `App`.** `App::new().add_plugins(DefaultPlugins)` gives windowing,
input, rendering, time, etc. Register systems into schedules: `Startup` (once)
and `Update` (every frame).
3. **Model data as components, globals as resources.** `#[derive(Component)]` for
per-entity data; `#[derive(Resource)]` for one-of-a-kind data (score, settings,
- the `Time` clock). In 0.19 `Resource` extends `Component`, so do not derive both.
+ the `Time` clock). Since 0.19 `Resource` extends `Component` and each resource is
+ stored on its own entity, so do not derive both.
4. **Write systems as plain functions.** Parameters declare data access: `Query<...>`
for entities, `Res<T>`/`ResMut<T>` for resources, `Commands` for deferred
spawn/despawn. Systems run in parallel when their accesses don't conflict.
@@ -54,7 +55,7 @@ procedural algorithms, pair with `game-ai` / `procedural-gen`.
```toml
# Cargo.toml — pin the version; the API differs across minor releases.
[dependencies]
-bevy = "0.19"
+bevy = "0.20"
```
```rust
@@ -169,9 +170,10 @@ impl Plugin for GameplayPlugin {
`elapsed_secs()`) in 0.16. Using the old name fails to compile.
- **Movement speed scales with frame rate** → multiply per-frame changes by
`time.delta_secs()`. Never assume a fixed frame time.
-- **Panic: "conflicting accesses" / "&mut T and &mut T"** → two `Query`s in one
- system both write the same component, or one reads while another writes overlapping
- entities. Make them disjoint with `With`/`Without`, or use `ParamSet`.
+- **Panic `error[B0001]`: "... accesses component(s) Transform in a way that conflicts
+ with a previous system parameter"** → two `Query`s in one system both write the same
+ component, or one reads while another writes overlapping entities. Make them disjoint
+ with `With`/`Without`, or use `ParamSet`.
- **`Camera2dBundle`/`SpriteBundle` not found** → bundles were deprecated in 0.15 and
removed in 0.16.
Spawn the components directly (`Camera2d`, `Sprite`, `Transform`); required
@@ -183,17 +185,40 @@ impl Plugin for GameplayPlugin {
not the one that spawned it.
- **System order assumed but not enforced** → systems run in parallel by default.
If `B` must follow `A`, add `(A, B).chain()` or an explicit ordering constraint.
-- **Deriving both `Resource` and `Component` in 0.19** → `Resource` now extends
- `Component`; derive `Resource` alone to avoid conflicting implementations.
+ To find order dependencies that only work by accident, shuffle the schedule in tests
+ with `ScheduleBuildSettings::shuffle_seed` (0.20, `debug` feature; see the reference).
+- **"conflicting implementations of trait `Component`" after deriving both `Resource`
+ and `Component`** → since 0.19 `Resource` extends `Component`; derive `Resource` alone.
+- **"Despawn everything" panics, or `Query<EntityMut>` next to a `Res<T>` panics with
+ `error[B0002]`** → since 0.19 every resource lives on an entity tagged `IsResource`,
+ so `Query<Entity>`/`EntityRef`/`EntityMut` match those entities too. Query your own
+ marker component, or add `Without<IsResource>` (`use bevy::ecs::resource::IsResource`).
+- **`On<Add, Player>` fails with "struct takes 1 generic argument but 2 generic
+ arguments were supplied"** → 0.20 moved the component into the lifecycle event:
+ write `On<Add<Player>>` (likewise `Insert<T>`, `Discard<T>`, `Remove<T>`, `Despawn<T>`).
+- **`OnExit`/`OnEnter` run again when "switching" to the current state** →
+ `NextState::set` always runs the transition schedules. Use `set_if_different` to skip
+ same-state transitions (renamed from `set_if_neq` in 0.20; calling `set_if_neq` on a
+ `ResMut<NextState<_>>` picks up the unrelated change-detection method and fails with
+ "can't compare `NextState`").
+- **"`text` does not live long enough" from `Name::new(text.as_str())`** → since 0.20
+ `Name` takes a `&'static str` literal or an owned `String`, not a borrowed `&str`;
+ pass `Name::new(text.clone())` or `Name::new(format!("Enemy {id}"))`.
+- **Overlapping sprites swap draw order after upgrading to 0.20** → sprites now render
+ through the `Mesh2d` backend, and draw order at equal `z` was never guaranteed. Give
+ sprites that can overlap distinct `Transform` z values.
- **Copy-pasting older Bevy snippets** → APIs shift between minor versions. The
- buffered event system became the message system in recent releases. Verify against
- the docs and migration guide for *your* pinned version; don't mix versions.
+ buffered event system became the message system: `EventReader`/`EventWriter`/
+ `add_event` no longer exist, so use `#[derive(Message)]`, `MessageReader`/
+ `MessageWriter`, and `app.add_message::<T>()`. Verify against the docs and migration
+ guide for *your* pinned version; don't mix versions.
## References
-- For schedules and `SystemSet` ordering, `States`/`OnEnter`/`OnExit`, change
- detection, `Commands` lifecycle and sync points, `ParamSet` for conflicting
- queries, and a version note on the events/observers API, read
+- For schedules and `SystemSet` ordering (including 0.20 weak ordering and schedule
+ shuffling), `States`/`OnEnter`/`OnExit` and state-scoped despawning, change
+ detection, `Commands` lifecycle and sync points, `ParamSet` and resource-entity
+ conflicts, `iter_many` results, and messages/observers in 0.20 syntax, read
`references/queries-and-scheduling.md`.
## Related skills
diff --git a/skills/other-engines/bevy-ecs/references/queries-and-scheduling.md b/skills/other-engines/bevy-ecs/references/queries-and-scheduling.md
index c478593..2d44ee6 100644
--- a/skills/other-engines/bevy-ecs/references/queries-and-scheduling.md
+++ b/skills/other-engines/bevy-ecs/references/queries-and-scheduling.md
@@ -1,4 +1,4 @@
-# Bevy queries & scheduling detail (0.19)
+# Bevy queries & scheduling detail (0.20)
Depth behind the ECS skill: query filters and access, schedules and ordering,
states, change detection, and the `Commands` lifecycle. Verify any borderline API
@@ -43,6 +43,37 @@ fn read_player(q: Query<&Transform, With<Player>>) {
Iterating with `for x in &query` is always valid and the safest default.
+### Many-entity access (0.20)
+
+`iter_many`, `iter_many_mut`, and their `unique`/`par_` variants take a list of
+entities and, since 0.20, yield `Result<Item, QueryEntityError>`: an entity that was
+despawned or doesn't match the query is an `Err`, not silently skipped.
+
+```rust
+#[derive(Component)]
+struct Health(f32);
+
+#[derive(Resource)]
+struct Targets(Vec<Entity>);
+
+fn check_targets(targets: Res<Targets>, q: Query<&Health>) {
+ for result in q.iter_many(targets.0.iter()) {
+ match result {
+ Ok(health) => { /* ... */ }
+ Err(err) => warn!("stale target: {err}"),
+ }
+ }
+}
+
+// .matched() keeps the pre-0.20 behaviour of skipping missing entities.
+fn heal_targets(targets: Res<Targets>, mut q: Query<&mut Health>) {
+ let mut iter = q.iter_many_mut(targets.0.iter()).matched();
+ while let Some(mut health) = iter.fetch_next() {
+ health.0 += 1.0;
+ }
+}
+```
+
## Avoiding conflicting access
Two systems can run in parallel only if their data accesses don't conflict. Two
@@ -63,6 +94,18 @@ fn swap(mut set: ParamSet<(
}
```
+3. **Resource entities** — since 0.19 each resource is stored on an entity tagged
+ `IsResource`, so broad queries (`Query<Entity>`, `Query<EntityRef>`,
+ `Query<EntityMut>`) match those entities too. `Query<EntityMut>` next to any
+ `Res<T>` panics with `error[B0002]`, and despawning every entity a `Query<Entity>`
+ returns panics. Query a marker component instead, or exclude resources:
+
+```rust
+use bevy::ecs::resource::IsResource; // not in the prelude
+
+fn inspect(entities: Query<EntityMut, Without<IsResource>>, score: Res<Score>) { /* ... */ }
+```
+
## Schedules and ordering
Built-in schedules you'll use most:
@@ -84,6 +127,23 @@ app.add_systems(Update, movement.before(collision));
app.add_systems(Update, camera_follow.after(movement));
```
+### Weak ordering (0.20)
+
+`.chain_weak()`, `.before_weak()`, and `.after_weak()` keep an ordering only between
+systems whose data access actually conflicts; systems that touch disjoint data may run
+in either order or in parallel. An earlier system that queues `Commands`, and any
+exclusive system, always keeps its place.
+
+```rust
+app.add_systems(Update, (tick_ai, tick_audio, tick_particles).chain_weak());
+```
+
+The scheduler can't see dependencies carried by interior mutability, channels, atomics,
+or global/`NonSend` state, so keep `.chain()` for those. 0.20 also orders several
+built-in sets weakly (`RenderSystems`, the `Core2d`/`Core3d` passes, and the UI
+`UiSystems` in `PostUpdate`): a custom system in one of those sets that relied on an
+earlier set finishing first, without a data dependency, needs an explicit `.after(...)`.
+
### System sets
Group systems into a `SystemSet` to order whole phases and attach shared run
@@ -101,10 +161,32 @@ app.add_systems(Update, (move_units, resolve).in_set(GameSet::Logic));
### Run conditions
```rust
+use bevy::time::common_conditions::on_timer; // not in the prelude
+use std::time::Duration;
+
app.add_systems(Update, pause_menu.run_if(in_state(AppState::Paused)));
app.add_systems(Update, autosave.run_if(on_timer(Duration::from_secs(30))));
```
+### Testing for hidden order dependencies (0.20)
+
+Systems with no ordering constraint run in an order the scheduler picks
+deterministically but arbitrarily, so code can work only by accident until an unrelated
+change reshuffles it. With Bevy's `debug` feature, shuffle that order in tests and try
+several seeds; explicit `.before`/`.after`/`.chain` constraints are kept.
+
+```rust
+// Cargo.toml: bevy = { version = "0.20", features = ["debug"] }
+use bevy::ecs::schedule::ScheduleBuildSettings;
+
+app.edit_schedule(Update, |schedule| {
+ schedule.set_build_settings(ScheduleBuildSettings {
+ shuffle_seed: Some(seed), // log the seed so a failing order can be replayed
+ ..default()
+ });
+});
+```
+
## States
`States` model app-wide modes (menu, playing, paused). Use `OnEnter`/`OnExit`
@@ -112,7 +194,7 @@ schedules for transition logic and `in_state` to gate `Update` systems.
```rust
#[derive(States, Default, Debug, Clone, PartialEq, Eq, Hash)]
-enum AppState { #[default] Menu, Playing }
+enum AppState { #[default] Menu, Playing, Paused }
app.init_state::<AppState>()
.add_systems(OnEnter(AppState::Playing), spawn_level)
@@ -121,6 +203,15 @@ app.init_state::<AppState>()
// Transition from a system:
fn start(mut next: ResMut<NextState<AppState>>) { next.set(AppState::Playing); }
+
+// set() always runs OnExit/OnEnter, even when the target is the current state.
+// set_if_different() skips same-state transitions (0.20 name; was set_if_neq).
+fn resume(mut next: ResMut<NextState<AppState>>) { next.set_if_different(AppState::Playing); }
+
+// Despawned automatically when Playing exits; no cleanup system needed.
+fn spawn_enemy(mut commands: Commands) {
+ commands.spawn((Enemy, DespawnOnExit(AppState::Playing)));
+}
```
## Change detection
@@ -130,6 +221,16 @@ react only to modified data — cheaper than recomputing every frame. Note: writ
through a `&mut T` marks it changed even if the value is identical; guard with a
value check if that matters.
+For a component that is checked with `Changed<T>` often but written rarely, 0.20 can
+keep a per-column summary tick so unchanged columns are skipped wholesale. Every write
+gets slightly more expensive, so opt in only where the queries dominate:
+
+```rust
+#[derive(Component)]
+#[component(summary_tick)]
+struct Inventory(Vec<u32>);
+```
+
## Commands lifecycle
`Commands` queue structural changes (spawn, despawn, insert/remove components,
@@ -139,6 +240,8 @@ insert resources). They are **deferred** and applied at the next sync point
- An entity spawned this frame is not in queries until a later system/stage.
- `commands.entity(e).despawn()` removes the entity; in 0.16+ this also removes its
children (the old explicit `despawn_recursive` was folded in).
+- `commands.despawn_all::<With<Enemy>>()` (0.20) despawns every matching entity in one
+ batched command, faster than despawning them one at a time.
```rust
fn spawn_bullet(mut commands: Commands) {
@@ -149,11 +252,59 @@ fn spawn_bullet(mut commands: Commands) {
For immediate, exclusive access to the whole `World` (one-off setup, complex
queries), use an exclusive system `fn(&mut World)` — it can't run in parallel, so
-use sparingly.
+use sparingly. Since 0.20 `&mut World` is an ordinary system parameter and no longer has
+to come first: `fn snapshot(mut runs: Local<u32>, world: &mut World)` is valid.
+Parameters that need their own world access still conflict with it.
+
+## Messages and observers (0.20)
+
+Two ways for systems to communicate:
+
+- **Messages** are buffered and pulled: writers queue them, and each reader drains the
+ new ones on its next run. Use them for per-frame streams (damage numbers, input
+ actions).
+- **Events + observers** are pushed: triggering an event runs every matching observer
+ right away (`commands.trigger` when the commands are applied, `world.trigger`
+ immediately). Use them for one-off reactions.
+
+```rust
+#[derive(Message)]
+struct ScoreChanged(u32);
-## Messages / observers — version caution
+app.add_message::<ScoreChanged>();
+
+fn send(mut writer: MessageWriter<ScoreChanged>) { writer.write(ScoreChanged(10)); }
+fn show(mut reader: MessageReader<ScoreChanged>) {
+ for msg in reader.read() { info!("+{}", msg.0); }
+}
+```
+
+```rust
+#[derive(Event)]
+struct LevelCleared { level: u32 }
+
+app.add_observer(|cleared: On<LevelCleared>| info!("level {} cleared", cleared.level));
+fn finish(mut commands: Commands) { commands.trigger(LevelCleared { level: 3 }); }
+
+// Entity-targeted event, observed on one entity.
+#[derive(EntityEvent)]
+struct Hit { entity: Entity, damage: f32 }
+
+fn spawn_player(mut commands: Commands) {
+ commands.spawn((Player, Health(10.0))).observe(|hit: On<Hit>, mut q: Query<&mut Health>| {
+ if let Ok(mut health) = q.get_mut(hit.entity) { health.0 -= hit.damage; }
+ });
+}
+fn hit(mut commands: Commands, player: Single<Entity, With<Player>>) {
+ commands.trigger(Hit { entity: *player, damage: 4.0 });
+}
+
+// Component lifecycle: in 0.20 the component is the event's type parameter.
+app.add_observer(|add: On<Add<Player>>| info!("player {} spawned", add.entity));
+// Also Insert<T>, Discard<T>, Remove<T>, Despawn<T>.
+// 0.17-0.19 wrote On<Add, Player>; 0.16 wrote Trigger<OnAdd, Player>.
+```
-Bevy's buffered event API evolved into the message API in recent releases, while
-observers remain event-oriented. If systems need buffered communication, look up
-the exact message/observer API for the pinned release rather than copying an
-example from a different version.
+`EventReader`, `EventWriter`, and `add_event` no longer exist. These APIs have moved in
+almost every recent release, so look up the exact message/observer API for the pinned
+version rather than copying an example from another one.