bevy-ecs-expert
Skill này làm gì
Hướng dẫn này chỉ cách xây dựng các trò chơi hiệu suất cao bằng cấu trúc ECS hướng dữ liệu của Bevy trong Rust. Bạn sẽ học cách tổ chức các phần mã (systems), tối ưu việc lấy dữ liệu (queries), quản lý thông tin toàn cục (resources) và chạy nhiều phần song song.
Khi nào nên dùng
- ✓Khi phát triển trò chơi với engine Bevy trong Rust.
- ✓Khi thiết kế các phần trò chơi cần chạy song song.
- ✓Khi tối ưu hiệu suất trò chơi bằng cách lấy dữ liệu hiệu quả.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/bevy-ecs-expert/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm sao để nhân vật của tôi di chuyển trên màn hình bằng Bevy ECS?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Bevy ECS tổ chức trò chơi thành “components” (dữ liệu đơn giản), “systems” (hàm thao tác trên dữ liệu này) và “resources” (dữ liệu toàn cục). Nó quản lý cách các system tương tác và chạy, giúp tối ưu hiệu suất.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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.
Câu hỏi thường gặp
“Components” là gì?
Components giống như những hộp chứa dữ liệu về một đối tượng trong trò chơi, như vị trí, vận tốc hoặc máu. Chúng được định nghĩa dưới dạng “struct” trong Rust.
“Systems” là gì?
Systems là các hàm làm cho mọi thứ xảy ra trong trò chơi. Chúng lấy components từ nhiều đối tượng và thay đổi chúng, chẳng hạn di chuyển nhân vật theo vận tốc của nó.
“Resources” là gì?
Resources là dữ liệu thuộc về toàn bộ trò chơi, không thuộc riêng đối tượng nào. Ví dụ gồm điểm số của người chơi hoặc trạng thái hiện tại của trò chơi (như “tạm dừng” hoặc “đang chơi”).
Chi tiết
Mô tả gốc của tác giả
Master Bevy's Entity Component System (ECS) in Rust, covering Systems, Queries, Resources, and parallel scheduling.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #4029
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.