bevy-ecs-expert

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

31,392 stars
Complexity: easy

About this skill

This skill transforms an AI agent into an expert on Bevy's powerful Entity Component System (ECS) framework in Rust. It provides a comprehensive guide to understanding and implementing data-oriented game logic, focusing on core Bevy ECS concepts such as Components, Systems, Queries, Resources, and advanced topics like parallel scheduling. The agent will internalize how to structure high-performance game logic, optimize data access to minimize cache misses, manage application state effectively, and leverage Bevy's parallel execution model for maximum efficiency. This knowledge empowers the AI to assist developers in designing, refactoring, and optimizing game systems, moving from traditional object-oriented paradigms to modern, data-oriented ECS patterns within the Bevy engine. It acts as an expert guide for generating correct, performant, and idiomatic Bevy ECS code.

Best use case

An AI agent can leverage this skill to provide expert guidance on Bevy ECS, generate optimized Rust code for game logic, explain complex ECS concepts, assist with refactoring existing code into a data-oriented design, and debug Bevy ECS-related development challenges.

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

The AI agent provides accurate, high-quality, and performant Bevy ECS code examples, delivers expert explanations and architectural guidance on Bevy ECS, and effectively helps debug and resolve issues related to Bevy ECS implementations. Users will receive clear, actionable advice leading to well-structured and optimized Bevy game logic.

Practical example

Example input

Explain how to define a custom component in Bevy ECS for a player's position and velocity. Then, create a system to update the player's position based on their velocity, ensuring parallel execution considerations are met.

Example output

```rust
use bevy::prelude::*;

// Define Components
#[derive(Component)]
pub struct Position { pub x: f32, pub y: f32 }

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

// Define a System to update position based on velocity
fn update_player_position(mut query: Query<(&mut Position, &Velocity)>) {
    for (mut position, velocity) in query.iter_mut() {
        position.x += velocity.x;
        position.y += velocity.y;
    }
}

// Minimal Bevy App for demonstration
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Update, update_player_position)
        // Example: Spawning an entity with these components
        .insert_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9)))
        .add_systems(Startup, setup_player)
        .run();
}

fn setup_player(mut commands: Commands) {
    commands.spawn(
        (Position { x: 0.0, y: 0.0 }, Velocity { x: 1.0, y: 0.5 })
    );
    println!("Player spawned. Run simulation to see position update.");
}
```

**Explanation:**

1.  **Components (`Position`, `Velocity`):** We define simple Rust structs and derive `Component`. This macro from Bevy makes them eligible to be attached to entities. They should generally hold only data, avoiding logic.

2.  **System (`update_player_position`):** This is a plain Rust function. It takes a `Query` as an argument, which is Bevy's way of selecting entities with specific components. `Query<(&mut Position, &Velocity)>` means it will find all entities that have both a `Position` and a `Velocity` component. `&mut Position` indicates we intend to modify the position, while `&Velocity` means we only need to read the velocity.

3.  **Parallel Execution:** Bevy's scheduler automatically ensures safe parallel execution of systems. When `update_player_position` runs, Bevy intelligently splits the `query.iter_mut()` loop across multiple threads if possible. Because each iteration of the loop only modifies the `Position` component of a *single* entity and reads the `Velocity` of that same entity, there are no data races between different entities. Bevy detects this independence and can parallelize the processing of different entities' positions concurrently without explicit locks or manual threading by the developer.

When to use this skill

  • When an AI agent needs to generate or analyze Rust code for game development using the Bevy engine.
  • When designing or implementing game systems that require parallel execution for optimal performance.
  • When optimizing game performance by advising on data-oriented design principles and minimizing cache misses in Bevy.
  • When refactoring existing object-oriented logic into efficient, data-oriented ECS patterns within the Bevy framework.

When not to use this skill

  • When developing games with engines other than Bevy (e.g., Unity, Godot, Unreal Engine).
  • When working on non-game applications that do not benefit from an ECS architecture.
  • When the primary task does not involve Rust programming or Bevy-specific paradigms.
  • When general game development knowledge is needed beyond the scope of ECS implementation.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/bevy-ecs-expert/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/bevy-ecs-expert/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/bevy-ecs-expert/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How bevy-ecs-expert Compares

Feature / Agentbevy-ecs-expertStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

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

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# 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`.

```rust
#[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.

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

```rust
#[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.

```rust
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

```rust
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.

```rust
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.

Related Skills

web-games

31392
from sickn33/antigravity-awesome-skills

Web browser game development principles. Framework selection, WebGPU, optimization, PWA.

Game DevelopmentClaude

vr-ar

31392
from sickn33/antigravity-awesome-skills

VR/AR development principles. Comfort, interaction, performance requirements.

Game DevelopmentClaude

pc-games

31392
from sickn33/antigravity-awesome-skills

PC and console game development principles. Engine selection, platform features, optimization strategies.

Game DevelopmentClaude

game-design

31392
from sickn33/antigravity-awesome-skills

Game design principles. GDD structure, balancing, player psychology, progression.

Game DevelopmentClaude

game-development

31392
from sickn33/antigravity-awesome-skills

Game development orchestrator. Routes to platform-specific skills based on project needs.

Game DevelopmentClaude

nestjs-expert

31392
from sickn33/antigravity-awesome-skills

You are an expert in Nest.js with deep knowledge of enterprise-grade Node.js application architecture, dependency injection patterns, decorators, middleware, guards, interceptors, pipes, testing strategies, database integration, and authentication systems.

Frameworks & LibrariesClaude

n8n-validation-expert

31392
from sickn33/antigravity-awesome-skills

Expert guide for interpreting and fixing n8n validation errors.

Workflow AutomationClaude

n8n-mcp-tools-expert

31392
from sickn33/antigravity-awesome-skills

Expert guide for using n8n-mcp MCP tools effectively. Use when searching for nodes, validating configurations, accessing templates, managing workflows, or using any n8n-mcp tool. Provides tool selection guidance, parameter formats, and common patterns.

Workflow AutomationClaude

mermaid-expert

31392
from sickn33/antigravity-awesome-skills

Create Mermaid diagrams for flowcharts, sequences, ERDs, and architectures. Masters syntax for all diagram types and styling.

Developer ToolsClaude

local-llm-expert

31392
from sickn33/antigravity-awesome-skills

Master local LLM inference, model selection, VRAM optimization, and local deployment using Ollama, llama.cpp, vLLM, and LM Studio. Expert in quantization formats (GGUF, EXL2) and local AI privacy.

Local LLM Development & OptimizationClaude

laravel-expert

31392
from sickn33/antigravity-awesome-skills

Senior Laravel Engineer role for production-grade, maintainable, and idiomatic Laravel solutions. Focuses on clean architecture, security, performance, and modern standards (Laravel 10/11+).

Coding & DevelopmentClaude

kotlin-coroutines-expert

31392
from sickn33/antigravity-awesome-skills

Expert patterns for Kotlin Coroutines and Flow, covering structured concurrency, error handling, and testing.

Knowledge & InformationClaude