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