bevyengine/bevy
Entity
An Entity is a 64-bit ID that identifies a logical thing in a World. It carries no data — components do that. An entity is two u32s packed together: an index (slot in the entity allocator) plus a generation number (incremented when the slot is reused).
Where it lives
crates/bevy_ecs/src/entity/mod.rs. The allocator and reuse logic are in the same directory.
Properties
- Cheap: an
EntityisCopyand 8 bytes. - Stable until despawn: an entity ID stays valid as long as the entity exists. After despawn the slot is reused, but with a different generation — a stale
Entitywill fail to look up. - Not portable across worlds: two different
Worlds may use the same numeric ID for different entities.
Spawning and despawning
let id = world.spawn((Health(100), Position(Vec3::ZERO))).id();
// later…
world.despawn(id);Or via commands:
fn spawn_player(mut commands: Commands) {
let id = commands.spawn((Health(100), Position(Vec3::ZERO))).id();
}Commands defers the actual creation until the next sync point in the schedule, so the entity ID is allocated immediately but the components aren't visible to other systems until later in the same tick.
Looking up an entity
let entity_ref = world.entity(id); // EntityRef (read)
let entity_mut = world.entity_mut(id); // EntityMut (read+write)
let pos = world.get::<Position>(id); // Option<&Position>A Query is the preferred way for systems to look up entities by component signature.
Hierarchies and relationships
Bevy's hierarchy is built on entities: parents and children are linked by ChildOf and Children components (the modern relationship API in crates/bevy_ecs/src/relationship/). The parent-child relationship is symmetric — adding ChildOf(parent) to a child automatically updates Children on the parent.
See also
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.