bevy-ecs-expert
できること
このガイドでは、Rustで使えるBevyのデータ指向ECS構造を用いて、高性能なゲームを作る方法を解説します。処理のまとまり(システム)の整理、データ取得(クエリ)の最適化、グローバルな情報(リソース)の管理、複数の処理の並列実行(並列処理)について学べます。
使う場面
- ✓Bevyエンジンを使ってRustでゲームを開発するとき。
- ✓ゲームの処理を並列で実行する必要がある部分を設計するとき。
- ✓データの取得を効率化して、ゲームのパフォーマンスを最適化したいとき。
スキルのリンク
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/bevy-ecs-expert/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Bevy ECSを使って、キャラクターを画面上で動かすにはどうすればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
Bevy ECSでは、ゲームを「コンポーネント」(単純なデータ)、「システム」(このデータを操作する関数)、「リソース」(グローバルなデータ)に分けて構成します。これらのシステムがどのように連携し、実行されるかを管理するため、パフォーマンスを最適化できます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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. Import bevy::prelude::*; add Reflect only when reflection/inspection is needed. The snippets are alternatives and do not duplicate Player/Velocity definitions in one scope.
#[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_secs();
transform.translation.y += velocity.y * time.delta_secs();
}
}
3. Managing Resources
Use Resource for global data (score, game state).
#[derive(Resource, Default)]
struct GameState {
score: u32,
}
fn score_system(mut game_state: ResMut<GameState>) {
game_state.score += 10;
}
The toy score_system increments each Update; use gameplay events or an explicit timer for meaningful scoring, rather than implying frame-rate-independent score behavior.
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
Queryfilters (With,Without,Changed) to reduce iteration count. - ✅ Do: Prefer
ResoverResMutwhen read-only access is sufficient to allow parallel execution. - ✅ Do: Use
Bundleto spawn complex entities atomically. - ❌ Don't: Store heavy logic inside Components; keep them as pure data.
- ❌ Don't: Use
RefCellor interior mutability inside components; prefer normal ECS borrowing; any interior-mutability design still needs valid Send/Sync and a clear synchronization reason.
Troubleshooting
Problem: System panic with "Conflict" error. Solution: The scheduler normally orders conflicting systems. Bevy B0001 often concerns incompatible queries inside one system; use disjoint With/Without filters or ParamSet as appropriate. Chaining two systems does not repair conflicting parameters inside a system. See Bevy B0001.
Limitations
- Pin the project’s Bevy version and check its migration/API guide. Current examples use delta_secs and required components; older Bevy versions may differ. Enemy/Dead are application-owned component markers and player.png is an application asset, not a bundled file. No engine compilation/performance benchmark is claimed here.
- 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.
よくある質問
「コンポーネント」とは何ですか?
コンポーネントは、ゲームのオブジェクトに関する情報(位置、速度、体力など)を保持する単純な箱のようなものです。Rustでは「struct」として定義します。
「システム」とは何ですか?
システムは、ゲーム内で処理を実行する関数です。さまざまなオブジェクトのコンポーネントを受け取って値を変更します。例えば、速度に基づいてキャラクターを動かすなどです。
「リソース」とは何ですか?
リソースは、特定のオブジェクトではなく、ゲーム全体に属するデータです。例として、プレイヤーのスコアや、現在のゲームの状態(「一時停止中」や「プレイ中」など)があります。
詳細
作者による元の説明
Master Bevy's Entity Component System (ECS) in Rust, covering Systems, Queries, Resources, and parallel scheduling.
人気
- GitHubのスター
- 48k
- ランキング
- #4029
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
00-andruia-consultant
48kエージェントがAIプロジェクトの立ち上げや改善を支援します。コードを分析し、ツールを提案し、スペイン語で行動計画を作成します。
007
48kエージェントがセキュリティ監査と脅威モデリングを行えるようにします。攻撃や脆弱性からプロジェクトを守るのに役立ちます。
10-andruia-skill-smith
48kエージェントがAIツールの作成や改善を支援します。ツールの動作を定義し、ドキュメントを書き、構造を検証します。
20-andruia-niche-intelligence
48kエージェントが特定の業界に関する要約を作成できるようにします。信頼できる情報源を使って、プロジェクトの背景、ルール、利用パターン、リスクを把握するのに役立ちます。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。