bevy/crates/bevy_ecs/src/world
JoJoJet 0174d632a5
Add a scope API for world schedules (#8387)
# Objective

If you want to execute a schedule on the world using arbitrarily complex
behavior, you currently need to use "hokey-pokey strats": remove the
schedule from the world, do your thing, and add it back to the world.
Not only is this cumbersome, it's potentially error-prone as one might
forget to re-insert the schedule.

## Solution

Add the `World::{try}schedule_scope{ref}` family of functions, which is
a convenient abstraction over hokey pokey strats. This method
essentially works the same way as `World::resource_scope`.

### Example

```rust
// Run the schedule five times.
world.schedule_scope(MySchedule, |world, schedule| {
    for _ in 0..5 {
        schedule.run(world);
    }
});
```

---

## Changelog

Added the `World::schedule_scope` family of methods, which provide a way
to get mutable access to a world and one of its schedules at the same
time.

---------

Co-authored-by: James Liu <contact@jamessliu.com>
2023-04-16 05:09:33 +00:00
..
entity_ref.rs bevy_ecs: add untyped methods for inserting components and bundles (#7204) 2023-03-21 00:33:11 +00:00
error.rs Add World::try_run_schedule (#8028) 2023-03-17 01:22:54 +00:00
identifier.rs Inline more ECS functions (#8083) 2023-04-12 19:52:06 +00:00
mod.rs Add a scope API for world schedules (#8387) 2023-04-16 05:09:33 +00:00
spawn_batch.rs Increase type safety and clarity for change detection (#7905) 2023-03-09 17:17:02 +00:00
unsafe_world_cell.rs Inline more ECS functions (#8083) 2023-04-12 19:52:06 +00:00
world_cell.rs Move all logic to UnsafeWorldCell (#7381) 2023-02-06 19:02:52 +00:00