Bevy Game Engine
Expert knowledge for developing games with Bevy, the data-driven game engine built in Rust with a focus on ergonomics, modularity, and performance.
When to Use This Skill
| Use this skill when... |
Use bevy-ecs-patterns instead when... |
| Starting a new Bevy game project |
Optimizing ECS query performance or archetype layout |
| Learning or applying basic ECS concepts |
Implementing complex system scheduling or ordering |
| Handling input (keyboard, mouse, gamepad) |
Using change detection (Changed<T>, Added<T>) |
| Managing game states and transitions |
Working with ParamSet or parallel query iteration |
| Loading and managing assets |
Designing entity relationship hierarchies |
| Setting up plugins and app structure |
Debugging archetype fragmentation or storage strategies |
| Working with events and resources |
Implementing batch spawn or deferred operations |
Core Expertise
Bevy Architecture
- Entity Component System (ECS): Data-oriented design with entities, components, and systems
- Plugin System: Modular game organization with reusable plugins
- Schedules: System ordering and execution timing
- Resources: Global singleton data accessible to systems
- Events: Typed message passing between systems
- States: Game state management and transitions
Rendering
- 2D Rendering: Sprites, sprite sheets, text rendering, 2D cameras
- 3D Rendering: PBR materials, meshes, lighting, shadows, cameras
- UI: bevy_ui for in-game interfaces
- Shaders: Custom WGSL shaders and render pipelines
Reference Files
The ECS core, project setup, and the command set below are everything a first
pass needs. Follow one link when the task calls for it — nothing under
references/ is loaded unless you open it.
| Path you are on |
File |
Carries |
| Reading player input |
references/input.md |
ButtonInput keyboard/mouse polling, pressed vs just-pressed, cursor position, gamepad and rebinding pointers |
| Loading assets, or driving the state machine |
references/assets-and-states.md |
AssetServer handles and LoadState gating, States enum, OnEnter/OnExit/run_if(in_state), NextState timing |
| Decoupling two systems that must communicate |
references/events.md |
#[derive(Event)], EventWriter/EventReader, add_event registration, the two-frame buffer and ordering caveat |
| Laying out a growing game, or chasing frame time |
references/project-architecture.md |
Directory layout, plugin/marker-component organization, query-filter and profiling guidance, bundles and system sets |
Key Capabilities
ECS Fundamentals
use bevy::prelude::*;
// Components are plain data structs
#[derive(Component)]
struct Player;
#[derive(Component)]
struct Health(f32);
#[derive(Component)]
struct Velocity(Vec2);
// Spawn entities with components
fn spawn_player(mut commands: Commands) {
commands.spawn((
Player,
Health(100.0),
Velocity(Vec2::ZERO),
SpriteBundle {
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
));
}
// Systems query for components
fn move_player(
time: Res<Time>,
mut query: Query<(&Velocity, &mut Transform), With<Player>>,
) {
for (velocity, mut transform) in &mut query {
transform.translation += velocity.0.extend(0.0) * time.delta_seconds();
}
}
App Structure
use bevy::prelude::*;
fn main() {
App::new()
// Default plugins (window, rendering, input, etc.)
.add_plugins(DefaultPlugins)
// Custom plugins
.add_plugins(GamePlugin)
// Resources
.insert_resource(GameSettings::default())
// Startup systems (run once)
.add_systems(Startup, setup)
// Update systems (run every frame)
.add_systems(Update, (
player_movement,
collision_detection,
update_score,
))
.run();
}
// Organize with plugins
pub struct GamePlugin;
impl Plugin for GamePlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn_player)
.add_systems(Update, player_input);
}
}
Essential Commands
# Create new Bevy project from the official template (recommended — ships an
# opinionated app skeleton, CI, and release profiles). See rust-plugin's
# cargo-generate skill.
cargo generate --git https://github.com/TheBevyFlock/bevy_new_2d --name my_game
# Or start from an empty crate
cargo new my_game
cd my_game
cargo add bevy
# Run with fast compile times (debug)
cargo run
# Run with optimizations
cargo run --release
# Enable dynamic linking for faster compiles (dev only)
cargo run --features bevy/dynamic_linking
# Common dev dependencies
cargo add bevy_egui # Debug UI
cargo add bevy_rapier2d # 2D physics
cargo add bevy_rapier3d # 3D physics
cargo add bevy_asset_loader # Asset loading helpers
cargo add leafwing-input-manager # Advanced input
Agentic Optimizations
| Context |
Command |
| Quick compile check |
cargo check 2>&1 | head -30 |
| Fast test run |
cargo test --lib -- --test-threads=1 -q |
| Run with fast compiles (dev) |
cargo run --features bevy/dynamic_linking |
| Run optimized build |
cargo run --release |
| Check for common issues |
cargo clippy -- -W clippy::all 2>&1 | head -50 |
| List plugins in project |
grep -rn "impl Plugin for" src/ --include="*.rs" |
| List game states |
grep -rn "derive.*States" src/ --include="*.rs" |
| Find event definitions |
grep -rn "derive.*Event" src/ --include="*.rs" |
| List dependencies |
cargo metadata --format-version=1 | jq -r '.packages[0].dependencies[].name' |
For detailed ECS patterns, advanced queries, and system scheduling, see the bevy-ecs-patterns skill.
1---
2created: 2025-12-16
3modified: 2026-08-07
4reviewed: 2025-12-16
5name: bevy-game-engine
6description: "Bevy game engine: ECS, rendering, input, and asset management. Use when building Bevy games, working with entities/components/systems, or mentioning Rust gamedev or 2D/3D games."
7user-invocable: false
8allowed-tools: Glob, Grep, Read, Bash(cargo *), Edit, Write, TodoWrite, WebFetch, WebSearch
9---
10
11# Bevy Game Engine
12
13Expert knowledge for developing games with Bevy, the data-driven game engine built in Rust with a focus on ergonomics, modularity, and performance.
14
15## When to Use This Skill
16
17| Use this skill when... | Use bevy-ecs-patterns instead when... |
18|------------------------|---------------------------------------|
19| Starting a new Bevy game project | Optimizing ECS query performance or archetype layout |
20| Learning or applying basic ECS concepts | Implementing complex system scheduling or ordering |
21| Handling input (keyboard, mouse, gamepad) | Using change detection (`Changed<T>`, `Added<T>`) |
22| Managing game states and transitions | Working with `ParamSet` or parallel query iteration |
23| Loading and managing assets | Designing entity relationship hierarchies |
24| Setting up plugins and app structure | Debugging archetype fragmentation or storage strategies |
25| Working with events and resources | Implementing batch spawn or deferred operations |
26
27## Core Expertise
28
29**Bevy Architecture**
30- **Entity Component System (ECS)**: Data-oriented design with entities, components, and systems
31- **Plugin System**: Modular game organization with reusable plugins
32- **Schedules**: System ordering and execution timing
33- **Resources**: Global singleton data accessible to systems
34- **Events**: Typed message passing between systems
35- **States**: Game state management and transitions
36
37**Rendering**
38- **2D Rendering**: Sprites, sprite sheets, text rendering, 2D cameras
39- **3D Rendering**: PBR materials, meshes, lighting, shadows, cameras
40- **UI**: bevy_ui for in-game interfaces
41- **Shaders**: Custom WGSL shaders and render pipelines
42
43## Reference Files
44
45The ECS core, project setup, and the command set below are everything a first
46pass needs. Follow one link when the task calls for it — nothing under
47`references/` is loaded unless you open it.
48
49| Path you are on | File | Carries |
50|---|---|---|
51| Reading player input | [`references/input.md`](references/input.md) | `ButtonInput` keyboard/mouse polling, pressed vs just-pressed, cursor position, gamepad and rebinding pointers |
52| Loading assets, or driving the state machine | [`references/assets-and-states.md`](references/assets-and-states.md) | `AssetServer` handles and `LoadState` gating, `States` enum, `OnEnter`/`OnExit`/`run_if(in_state)`, `NextState` timing |
53| Decoupling two systems that must communicate | [`references/events.md`](references/events.md) | `#[derive(Event)]`, `EventWriter`/`EventReader`, `add_event` registration, the two-frame buffer and ordering caveat |
54| Laying out a growing game, or chasing frame time | [`references/project-architecture.md`](references/project-architecture.md) | Directory layout, plugin/marker-component organization, query-filter and profiling guidance, bundles and system sets |
55
56## Key Capabilities
57
58**ECS Fundamentals**
59```rust
60use bevy::prelude::*;
61
62// Components are plain data structs
63#[derive(Component)]
64struct Player;
65
66#[derive(Component)]
67struct Health(f32);
68
69#[derive(Component)]
70struct Velocity(Vec2);
71
72// Spawn entities with components
73fn spawn_player(mut commands: Commands) {
74 commands.spawn((
75 Player,
76 Health(100.0),
77 Velocity(Vec2::ZERO),
78 SpriteBundle {
79 transform: Transform::from_xyz(0.0, 0.0, 0.0),
80 ..default()
81 },
82 ));
83}
84
85// Systems query for components
86fn move_player(
87 time: Res<Time>,
88 mut query: Query<(&Velocity, &mut Transform), With<Player>>,
89) {
90 for (velocity, mut transform) in &mut query {
91 transform.translation += velocity.0.extend(0.0) * time.delta_seconds();
92 }
93}
94```
95
96**App Structure**
97```rust
98use bevy::prelude::*;
99
100fn main() {
101 App::new()
102 // Default plugins (window, rendering, input, etc.)
103 .add_plugins(DefaultPlugins)
104 // Custom plugins
105 .add_plugins(GamePlugin)
106 // Resources
107 .insert_resource(GameSettings::default())
108 // Startup systems (run once)
109 .add_systems(Startup, setup)
110 // Update systems (run every frame)
111 .add_systems(Update, (
112 player_movement,
113 collision_detection,
114 update_score,
115 ))
116 .run();
117}
118
119// Organize with plugins
120pub struct GamePlugin;
121
122impl Plugin for GamePlugin {
123 fn build(&self, app: &mut App) {
124 app.add_systems(Startup, spawn_player)
125 .add_systems(Update, player_input);
126 }
127}
128```
129
130## Essential Commands
131
132```bash
133# Create new Bevy project from the official template (recommended — ships an
134# opinionated app skeleton, CI, and release profiles). See rust-plugin's
135# cargo-generate skill.
136cargo generate --git https://github.com/TheBevyFlock/bevy_new_2d --name my_game
137
138# Or start from an empty crate
139cargo new my_game
140cd my_game
141cargo add bevy
142
143# Run with fast compile times (debug)
144cargo run
145
146# Run with optimizations
147cargo run --release
148
149# Enable dynamic linking for faster compiles (dev only)
150cargo run --features bevy/dynamic_linking
151
152# Common dev dependencies
153cargo add bevy_egui # Debug UI
154cargo add bevy_rapier2d # 2D physics
155cargo add bevy_rapier3d # 3D physics
156cargo add bevy_asset_loader # Asset loading helpers
157cargo add leafwing-input-manager # Advanced input
158```
159
160## Agentic Optimizations
161
162| Context | Command |
163|---------|---------|
164| Quick compile check | `cargo check 2>&1 \| head -30` |
165| Fast test run | `cargo test --lib -- --test-threads=1 -q` |
166| Run with fast compiles (dev) | `cargo run --features bevy/dynamic_linking` |
167| Run optimized build | `cargo run --release` |
168| Check for common issues | `cargo clippy -- -W clippy::all 2>&1 \| head -50` |
169| List plugins in project | `grep -rn "impl Plugin for" src/ --include="*.rs"` |
170| List game states | `grep -rn "derive.*States" src/ --include="*.rs"` |
171| Find event definitions | `grep -rn "derive.*Event" src/ --include="*.rs"` |
172| List dependencies | `cargo metadata --format-version=1 \| jq -r '.packages[0].dependencies[].name'` |
173
174For detailed ECS patterns, advanced queries, and system scheduling, see the bevy-ecs-patterns skill.