mcpField
B
bevy-ecs-patterns

bevy-ecs-patterns

github.com/laurigatesDevelopment5952 installsUpdated 1d ago
Repository

About bevy-ecs-patterns

A skill for Bevy game developers working with advanced ECS patterns, covering queries, scheduling, change detection, and performance techniques.

Key features

  1. 01Complex queries and filters
  2. 02Query state and caching
  3. 03Entity relationships and hierarchies
  4. 04System scheduling and dependencies
  5. 05Change detection and reactive systems
  6. 06Parallel iteration and ParamSet

Use cases

  1. 01Optimize ECS query performance
  2. 02Design complex entity hierarchies
  3. 03Configure system ordering and run conditions
  4. 04Investigate archetype fragmentation

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/laurigates/claude-plugins --skill bevy-ecs-patterns

After installing, type/bevy-ecs-patternsin Claude Code to confirm it loaded.

Bundled filesREFERENCE.md

Details

From the project README

Bevy ECS Patterns

Advanced patterns and techniques for Bevy's Entity Component System, focusing on performance, maintainability, and complex game architectures.

When to Use This Skill

Use this skill when...Use bevy-game-engine instead when...
Optimizing ECS query performanceSetting up a new Bevy project from scratch
Implementing complex entity relationships or hierarchiesLearning basic ECS concepts (components, systems, resources)
Designing system scheduling and orderingHandling input, assets, or game states
Using change detection (Changed<T>, Added<T>)Writing basic game logic or app structure
Working with ParamSet, parallel iteration, or batch operationsConfiguring rendering, UI, or audio
Debugging archetype fragmentation or storage strategiesAdding plugins or common Bevy dependencies

Core Expertise

Advanced Queries

  • Complex query filters and combinations
  • Query state and caching
  • Entity relationships and hierarchies
  • Parallel iteration strategies

System Scheduling

  • System ordering and dependencies
  • Run conditions and gating
  • System sets and scheduling
  • Fixed timestep systems

Change Detection

  • Changed<T> and Added<T> filters
  • Ref<T> for change tracking
  • Efficient reactive systems

Advanced Query Patterns

Query Filters

use bevy::prelude::*;

// Multiple filters
fn targeting_system(
    query: Query<
        (&Transform, &mut Target),
        (With<Enemy>, Without<Dead>, Changed<Health>)
    >,
) {
    for (transform, mut target) in &query {
        // Only enemies that are alive and recently damaged
    }
}

// Optional components
fn flexible_system(
    query: Query<(&Transform, Option<&Velocity>, Option<&Acceleration>)>,
) {
    for (transform, velocity, acceleration) in &query {
        if let Some(vel) = velocity {
            // Has velocity
        }
    }
}

// Or filters
fn pickup_system(
    query: Query<Entity, Or<(With<HealthPickup>, With<AmmoPickup>)>>,
) {
    for entity in &query {
        // Process any pickup type
    }
}

Multiple Queries with Conflicts

// Use ParamSet when queries have conflicting access
fn combat_system(
    mut param_set: ParamSet<(
        Query<&mut Health, With<Player>>,
        Query<&mut Health, With<Enemy>>,
    )>,
) {
    // Access one query at a time
    for mut health in param_set.p0().iter_mut() {
        health.0 += 1.0; // Heal player
    }

    for mut health in param_set.p1().iter_mut() {
        health.0 -= 10.0; // Damage enemies
    }
}

// Query transmutation for flexible access
fn dynamic_query(
    all_entities: Query<(Entity, &Transform)>,
    players: Query<&Player>,
) {
    for (entity, transform) in &all_entities {
        if players.get(entity).is_ok() {
            // This is a player
        }
    }
}

Entity Relationships

// Parent-child hierarchies
#[derive(Component)]
struct Inventory;

#[derive(Component)]
struct InventorySlot(usize);

fn spawn_inventory(mut commands: Commands) {
    commands.spawn((Inventory, SpatialBundle::default()))
        .with_children(|parent| {
            for i in 0..10 {
                parent.spawn((InventorySlot(i), SpriteBundle::default()));
            }
        });
}

// Query parent from child
fn child_system(
    children: Query<(&InventorySlot, &Parent)>,
    parents: Query<&Inventory>,
) {
    for (slot, parent) in &children {
        if let Ok(inventory) = parents.get(parent.get()) {
            // Access parent inventory
        }
    }
}

// Query children from parent
fn parent_system(
    parents: Query<&Children, With<Inventory>>,
    slots: Query<&InventorySlot>,
) {
    for children in &parents {
        for &child in children.iter() {
            if let Ok(slot) = slots.get(child) {
                // Access child slot
            }
        }
    }
}

Agentic Optimizations

ContextCommand
Quick compile checkcargo check 2>&1 | head -30
Fast test runcargo test --lib -- --test-threads=1 -q
Check ECS usage errorscargo clippy -- -W clippy::all 2>&1 | head -50
List components in projectgrep -rn "derive(Component)" src/ --include="*.rs"
List systems in projectgrep -rn "fn.*Query<" src/ --include="*.rs"
Find system orderinggrep -rn "\.add_systems|\.chain()|\.after(|\.before(" src/ --include="*.rs"
Check for ParamSet usagegrep -rn "ParamSet" src/ --include="*.rs"

For system scheduling, change detection, performance patterns, custom entity commands, and design best practices, see REFERENCE.md.

Comments

Markdown supported