一键导入
bevy-commands
Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Reference for Avian physics engine — rigid bodies, colliders, joints, spatial queries, collision events, character controllers, and debug rendering.
Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading.
Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings.
Reference for Bevy Scene Notation (BSN) — the bsn! macro for defining inline scenes with components, children, relationships, observers, and dynamic props.
Reference for cameras in Bevy — Camera2d, Camera3d, viewports, projection, render layers, mouse-to-world, and free camera controllers.
Reference for bevy_enhanced_input — observer-based input manager with actions, contexts, bindings, conditions, modifiers, presets, and mocking.
| name | bevy-commands |
| description | Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing. |
| metadata | {"crate":"bevy_ecs","bevy":"0.19"} |
Commands is a system parameter that queues mutations. They execute together at the next schedule transition (via ApplyDeferred).
fn spawn(mut commands: Commands) {
commands.spawn_empty();
}
commands.spawn(Player).insert(Transform::default());
// or with a tuple bundle
commands.spawn((Player, Transform::from_xyz(1., 1., 1.)));
#[derive(Component)]
#[require(Transform)]
struct Player;
// now: commands.spawn(Player) auto-adds Transform
spawn/spawn_empty return EntityCommands for chaining:
commands
.spawn(Player)
.insert(Transform::default())
.insert(Name::new("Player 1"));
for entity in &query {
commands.entity(entity).despawn();
}
Commands don't execute immediately — they're queued until the next ApplyDeferred system runs (typically at schedule boundaries).
Implement the Command trait:
struct SpawnPlanet { radius: f32, position: Vec2 }
impl Command for SpawnPlanet {
fn apply(self, world: &mut World) {
let mesh = world.resource_scope(|_w, mut meshes: Mut<Assets<Mesh>>| {
meshes.add(Circle::new(self.radius))
});
// ...
world.spawn((Planet::new(self.radius), Mesh2d(mesh), Transform::from_translation(self.position.extend(0.))));
}
}
// usage:
commands.queue(SpawnPlanet { radius: 100., position: Vec2::ZERO });
trait MyExt {
fn do_thing(&mut self);
}
impl<'w, 's> MyExt for Commands<'w, 's> {
fn do_thing(&mut self) { info!("thing done"); }
}
use bevy::ecs::world::CommandQueue;
let mut world = World::default();
let mut queue = CommandQueue::default();
queue.push(MyCommand);
queue.apply(&mut world);