Spawning and Moving Entities
Put things on screen.
Commands: Deferred Spawning
You can't mutate the World directly while systems run in parallel. Instead, you queue structural changes through Commands.
Spawning, despawning, and adding components are recorded and applied at the end of the schedule stage, keeping access safe.
fn setup(mut commands: Commands) {
commands.spawn_empty();
}Spawning with a Bundle
A bundle is a group of components inserted together. The simplest bundle is just a tuple of components.
Bevy treats each tuple element as a component to attach, so one spawn call can give an entity all its starting data.
fn setup(mut commands: Commands) {
commands.spawn((
Position { x: 0.0, y: 0.0 },
Velocity { x: 1.5, y: 0.0 },
Player,
));
}All lessons in this course
- The ECS Mindset
- Spawning and Moving Entities
- Handling Input and Time
- Collisions and Game State