Skip to content

Ergonomic tools for working with Commands from &mut World #3096

@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

Even when working with exclusive world access, work often needs to be deferred to satisfy soundness.

This occurs most commonly when iterating over a query or in other looping contexts.

What solution would you like?

Add World::commands(), which fetches a fresh instance of Commands.

Add World::apply_commands(), for a simple

What alternative(s) have you considered?

This is a partial, tightly-scoped alternative to some of the frustrations that inspired bevyengine/rfcs#42.

Additional context

World::apply_commands can currently be achieved with this snippet:

use bevy::prelude::*;
use bevy::ecs::system::SystemState;

let world = World::new();

let mut system_state = SystemState::<Commands>::new(&mut world);

// Manually adding a command to the list to verify that this works
let mut commands = system_state.get_mut();
commands.spawn();

// Applies all accumulated commands to the world, causing them to take immediate effect
system_state.apply(&mut world);

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions