Skip to content

Conversation

joseph-gio
Copy link
Member

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

// 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.

@joseph-gio joseph-gio added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events labels Apr 14, 2023
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed C-Feature A new feature, making something new possible labels Apr 14, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice: I was hoping we'd get these.

@alice-i-cecile alice-i-cecile added this to the 0.11 milestone Apr 14, 2023
@james7132 james7132 added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 15, 2023
@github-actions
Copy link
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@james7132 james7132 removed the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 15, 2023
@james7132 james7132 self-requested a review April 15, 2023 00:44
@hymm
Copy link
Contributor

hymm commented Apr 15, 2023

I'm not a big fan of the proliferation of the _ref functions, given the footgun with double boxing the label. Code quality looks good otherwise.

@joseph-gio
Copy link
Member Author

joseph-gio commented Apr 15, 2023

I'm not a big fan of the proliferation of the _ref functions, given the footgun with double boxing the label. Code quality looks good otherwise.

I agree. I think we should merge the ref variants with the owned versions of these functions, but I'm including them for now for consistency with how {try_}run_schedule already works.

@alice-i-cecile alice-i-cecile requested a review from hymm April 15, 2023 20:05
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 15, 2023
@james7132 james7132 enabled auto-merge April 16, 2023 04:57
@james7132 james7132 added this pull request to the merge queue Apr 16, 2023
Merged via the queue into bevyengine:main with commit 0174d63 Apr 16, 2023
@joseph-gio joseph-gio deleted the schedule-scope branch April 16, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants