Open-Source Wikis

/

Bevy

/

Primitives

/

World

bevyengine/bevy

World

A World is the container that owns entities, components, resources, and schedules. App (and SubApp) wraps a World plus a runner.

Where it lives

crates/bevy_ecs/src/world/mod.rs (4,600 lines, the largest single file in the workspace).

Anatomy

A World holds:

  • Entities — an entity allocator that hands out Entity IDs and tracks their generations.
  • Components — per-archetype tables and sparse-set columns.
  • ResourcesTypeId → Box<dyn Any> map of singletons.
  • Schedules — a Schedules resource holding a map of ScheduleLabel → Schedule.
  • Change ticks — the world's monotonic change_tick counter.

The Resources and Components registries are shared by all worlds in the same process via the bevy_ecs::component registry hash.

Working with a world directly

World has the unchecked, blocking API. Most user code uses Commands (deferred) and Query (parallel-friendly) instead. But sometimes you need direct access:

let id = world.spawn((Health(100),)).id();
let h = world.get::<Health>(id).unwrap();
let res = world.resource::<Time>();
world.insert_resource(MyResource);
world.run_schedule(MyLabel);

World::run_schedule is how the runner drives the main loop: it calls world.run_schedule(Main) once per frame.

EntityRef / EntityMut

For sustained per-entity work, get an EntityRef or EntityMut:

let mut e = world.entity_mut(id);
let h = e.get::<Health>().unwrap();
e.insert(Velocity(Vec3::X));
e.remove::<Position>();
e.despawn();

These pattern-match against Entity+component lookups efficiently.

SubApp boundary

The render pipeline runs in a separate World inside the RenderSubApp. The two worlds synchronize once per frame at the ExtractSchedule. See Architecture.

Querying without a system

let mut q = world.query::<&Health>();
for h in q.iter(&world) {
    println!("{}", h.0);
}

Useful when you can't use the system parameter form (e.g., in tests or one-shot tools).

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

World – Bevy wiki | Factory