Skip to content
bevy-ecs-expert logo

Bevy ECS Expert

bevy-ecs-expert

Master Bevy's Entity Component System (ECS) in Rust, covering Systems, Queries, Resources, and parallel scheduling.

SKILL.md

Full skill instructions

Bevy ECS Expert

Overview

A guide to building high-performance game logic using Bevy's data-oriented ECS architecture. Learn how to structure systems, optimize queries, manage resources, and leverage parallel execution.

When to Use This Skill

  • Use when developing games with the Bevy engine in Rust.
  • Use when designing game systems that need to run in parallel.
  • Use when optimizing game performance by minimizing cache misses.
  • Use when refactoring object-oriented logic into data-oriented ECS patterns.

Step-by-Step Guide

1. Defining Components

Use simple structs for data. Derive Component and Reflect.

#[derive(Component, Reflect, Default)]
#[reflect(Component)]
struct Velocity {
    x: f32,
    y: f32,
}

#[derive(Component)]
struct Player;

2. Writing Systems

Systems are regular Rust functions that query components.

fn movement_system(
    time: Res<Time>,
    mut query: Query<(&mut Transform, &Velocity), With<Player>>,
) {
    for (mut transform, velocity) in &mut query {
        transform.translation.x += velocity.x * time.delta_seconds();
        transform.translation.y += velocity.y * time.delta_seconds();
    }
}

3. Managing Resources

Use Resource for global data (score, game state).

#[derive(Resource)]
struct GameState {
    score: u32,
}

fn score_system(mut game_state: ResMut<GameState>) {
    game_state.score += 10;
}

4. Scheduling Systems

Add systems to the App builder, defining execution order if needed.

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .init_resource::<GameState>()
        .add_systems(Update, (movement_system, score_system).chain())
        .run();
}

Examples

Example 1: Spawning Entities with Require Component

use bevy::prelude::*;

#[derive(Component, Reflect, Default)]
#[require(Velocity, Sprite)]
struct Player;

#[derive(Component, Default)]
struct Velocity {
    x: f32,
    y: f32,
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn((
        Player,
        Velocity { x: 10.0, y: 0.0 },
        Sprite::from_image(asset_server.load("player.png")), 
    ));
}

Example 2: Query Filters

Use With and Without to filter entities efficiently.

fn enemy_behavior(
    query: Query<&Transform, (With<Enemy>, Without<Dead>)>,
) {
    for transform in &query {
        // Only active enemies processed here
    }
}

Best Practices

  • ✅ Do: Use Query filters (With, Without, Changed) to reduce iteration count.
  • ✅ Do: Prefer Res over ResMut when read-only access is sufficient to allow parallel execution.
  • ✅ Do: Use Bundle to spawn complex entities atomically.
  • ❌ Don't: Store heavy logic inside Components; keep them as pure data.
  • ❌ Don't: Use RefCell or interior mutability inside components; let the ECS handle borrowing.

Troubleshooting

Problem: System panic with "Conflict" error. Solution: You are likely trying to access the same component mutably in two systems running in parallel. Use .chain() to order them or split the logic.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

More Cloud & Infrastructure skills

web-design-guidelines logo
Cloud & Infrastructure

web-design-guidelines

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

31.9K 700.6K
View
microsoft-foundry logo
Cloud & Infrastructure

microsoft-foundry

End-to-end deployment, evaluation, and management of AI agents on Microsoft Foundry.

1.5K 630.6K
View
azure-diagnostics logo
Cloud & Infrastructure

azure-diagnostics

Systematic diagnosis and remediation for Azure production issues using AppLens, Monitor, and resource health.

1.5K 620.8K
View
azure-prepare logo
Cloud & Infrastructure

azure-prepare

Prepare Azure applications for deployment with infrastructure-as-code, configuration, and containerization.

1.5K 620.3K
View
azure-ai logo
Cloud & Infrastructure

azure-ai

Unified access to Azure AI services: Search, Speech, OpenAI, and Document Intelligence.

1.5K 620.1K
View
azure-deploy logo
Cloud & Infrastructure

azure-deploy

Execute Azure deployments for prepared applications with built-in error recovery and validation.

1.5K 620K
View
azure-validate logo
Cloud & Infrastructure

azure-validate

Pre-deployment validation for Azure readiness with configuration, infrastructure, RBAC, and identity checks.

1.5K 619.4K
View
azure-storage logo
Cloud & Infrastructure

azure-storage

Unified access to Azure blob storage, file shares, queues, tables, and data lake services.

1.5K 618.9K
View
entra-app-registration logo
Cloud & Infrastructure

entra-app-registration

Microsoft Entra ID app registration, OAuth 2.0 configuration, and MSAL integration for secure application authentication.

1.5K 618.6K
View
appinsights-instrumentation logo
Cloud & Infrastructure

appinsights-instrumentation

Guidance and reference material for instrumenting webapps with Azure Application Insights.

1.5K 618.3K
View
azure-resource-lookup logo
Cloud & Infrastructure

azure-resource-lookup

Fast discovery and inventory of Azure resources across subscriptions using Resource Graph queries.

1.5K 618.3K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View