Bevy ecs

From huytran1120/vie-agentic-skills · View interactive version

Bevy ecs is an AI agent skill from the GitHub repository huytran1120/vie-agentic-skills. Structure a Bevy app around its Entity Component System: build the App with plugins, define Component/Resource types, write systems with Query/Res/Commands, filter and order systems, and use the Time resource for frame-rate-independent motion. Use when building or debugging a Bevy game in Rust — whe

How to use this skill

Skill file

Bevy ECS

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.20. If the project

already pins another release, keep that release and use its matching migration guide.

When to use

systems that query entities, ordering/filtering systems, or fixing

borrow-conflict panics and frame-dependent movement.

add_systems, Query, or Commands.

When not to use: this is the ECS core. Deep rendering, custom shaders/

pipelines, UI layout, and audio are separate concerns. For engine-agnostic AI or

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.20"; never silently migrate an existing project

across a Bevy minor release. Treat the matching docs and migration guides as truth.

  1. Build the App. App::new().add_plugins(DefaultPlugins) gives windowing,

input, rendering, time, etc. Register systems into schedules: Startup (once)

and Update (every frame).

  1. 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). Since 0.19 Resource extends Component and each resource is

stored on its own entity, so do not derive both.

  1. 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.

  1. Drive motion by time.delta_secs() so speed is frame-rate independent.
  2. Order only what must be ordered with .chain() or explicit constraints;

gate systems with run_if. Group related setup into Plugins. Build with

cargo run and read the panics — Bevy reports conflicting queries at startup.

Patterns

1. Cargo.toml + minimal App

# Cargo.toml — pin the version; the API differs across minor releases.
[dependencies]
bevy = "0.20"
// main.rs
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)            // window, input, render, time, ...
        .add_systems(Startup, setup)            // runs once at startup
        .add_systems(Update, move_players)      // runs every frame
        .run();
}

2. Components, resources, and spawning

#[derive(Component)]
struct Player;

#[derive(Component)]
struct Velocity(Vec2);

#[derive(Resource)]
struct Score(u32);

fn setup(mut commands: Commands) {
    commands.insert_resource(Score(0));

    // Camera2d is a component with required components (bundles removed in 0.16);
    // spawning it pulls in Transform, Camera, etc. automatically.
    commands.spawn(Camera2d);

    // Spawn an entity as a tuple of components.
    commands.spawn((
        Player,
        Velocity(Vec2::new(150.0, 0.0)),
        Transform::from_xyz(0.0, 0.0, 0.0),
    ));
}

3. A system with a query + the Time resource

// Iterate every entity that has BOTH Velocity and Transform; mutate Transform.
fn move_players(time: Res<Time>, mut query: Query<(&Velocity, &mut Transform)>) {
    for (velocity, mut transform) in &mut query {
        // delta_secs() is f32 seconds (renamed from delta_seconds() in 0.16).
        transform.translation += velocity.0.extend(0.0) * time.delta_secs();
    }
}

4. Query filters (With / Without / Changed)

// Only entities tagged Player (the Player component itself isn't read).
fn aim_player(mut q: Query<&mut Transform, With<Player>>) { /* ... */ }

// Disjoint two mutable Transform queries so they don't conflict at runtime.
fn separate(
    mut players: Query<&mut Transform, With<Player>>,
    mut enemies: Query<&mut Transform, Without<Player>>,
) { /* ... */ }

// React only when Health changed since last run (change detection).
fn on_health_change(q: Query<&Health, Changed<Health>>) {
    for health in &q { /* update the HUD, etc. */ }
}

5. Resources: read and write

fn add_points(mut score: ResMut<Score>) {
    score.0 += 10;                 // ResMut = write access
}

fn show_score(score: Res<Score>) {
    info!("score: {}", score.0);   // Res = read access
}

6. Ordering, run conditions, and plugins

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, GameplayPlugin))
        // .chain() forces order: damage resolves before death is checked.
        .add_systems(Update, (apply_damage, check_deaths).chain())
        // run_if gates a system on a condition each frame.
        .add_systems(Update, spawn_wave.run_if(wave_timer_finished))
        .run();
}

struct GameplayPlugin;
impl Plugin for GameplayPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource(Score(0))
           .add_systems(Startup, setup)
           .add_systems(Update, (move_players, add_points));
    }
}

Pitfalls

elapsed_secs()) in 0.16. Using the old name fails to compile.

time.delta_secs(). Never assume a fixed frame time.

with a previous system parameter"** → two Querys 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.

removed in 0.16.

Spawn the components directly (Camera2d, Sprite, Transform); required

components fill in the rest.

(or #[derive(Resource)] for a resource).

deferred and applied at the next sync point. Read the entity in a subsequent system,

not the one that spawned it.

If B must follow A, add (A, B).chain() or an explicit ordering constraint.

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).

and Component** → since 0.19 Resource extends Component; derive Resource alone.

error[B0002] (or B0001, depending on parameter order)** → 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).

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>).

flattened pointer events: observe On<PointerClick> / On<PointerPress>, and read

click.pointer.position (a Vec2) instead of the old pointer_location.

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").

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}")).

through the Mesh2d backend, and draw order at equal z was never guaranteed. Give

sprites that can overlap distinct Transform z values.

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

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

VAS installation notes

Imported from gamedev-skills/awesome-gamedev-agent-skills at

19d93f97c9c1ea0f8b306e77aa81e0d3e352d3e9, Apache-2.0.

Copyright 2026 Abhishek Barali and the awesome-gamedev-agent-skills contributors.

The complete upstream LICENSE and NOTICE accompany this standalone skill.

Third-party notices, including the Go-Fonts license where provided, remain intact.

Only documented VAS naming, router-path adaptations and these notes differ;

supporting files and executable modes are preserved.

Use Copy Agent Prompt in the VAS catalog or ./vas install <canonical-id> --target <agent>.

VAS uses its existing agent-folder mapping and CLI-compatible receipt. Installing

a skill only copies/links its payload; it never runs bundled Python/Luau/Go code,

installs engines, SDKs, packages, plugins or MCP servers, connects accounts,

generates assets through paid services, uploads builds or publishes a game.

Review code and request permission before installation, execution, downloads,

external services, private-data submission, purchases or publishing.

Respect the existing project's pinned engine/dependency versions. Baselines in

the upstream runbooks are snapshots, not claims about the newest release.

Actual use may need the matching engine, Go/.NET/Luau/Node toolchain, SDK,

hardware or platform account. create-game-assets' optional image helpers need

Pillow>=10,<14; no Pillow or other runtime dependency is installed automatically.

Generated Ebitengine projects fetch their own Go modules only with approval;

the bundled Go-Fonts notice does not change the license of this runbook.

Storefront publishing, signing credentials and paid asset generation are separate,

explicitly authorized actions. Missing prerequisites or failed commands are errors,

not evidence that a game works or has shipped.

Collection names performance-optimization and godot-export mean VAS canonical IDs

gamedev-performance-optimization and gamedev-godot-export respectively, not the

unrelated existing application-performance or Blender-export skills.

Other source skill names retain their canonical IDs and installed folder names.

Cross-skill composition recommendations do not imply that other independent

skills or external tools have been installed. Each specialized skill includes

its own complete local references, helpers and assets. For automatic selection

across the collection, the separately installable router includes all 77 original

specialized payloads as read-only companions under bundled/skills/, with

RUNBOOK.md filenames rather than additional auto-discovered SKILL.md files.

Read only the selected companion and its references on demand; never execute

its helpers automatically. Bundled companions are references, not extra catalog

records or separately registered agent skills. External engines, documentation,

SDKs, services and generated project's dependencies remain separate prerequisites.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.