Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Since the issue was made, Bevy's plugins have been split into three stages that are (typically) run before app update: Build, finish and cleanup. They also have a
ready
method to delay the switch from the build to the finish phase.This allows plugins to delay up to twice while waiting on other plugins, but the specific dependency is implicit even when reading the code and the ordering of plugins matters. Solve this by making plugin building concurrent.
Also, I've just now seen #8607, which also makes plugins asynchronous. I'll need to take a closer look, but afaik it has the goal of running on
bevy_tasks
and doesn't address dependencies / plugin ordering (as it build plugins one at a time).Solution
Adds
Plugin::build_async
, which runs concurrently for all plugins. The plugin can wait for the world to reach whatever state it needs to continue. While you can define a custom condition, there's also a helper for waiting on a resource; please suggest other ones.This is intended to replace the old plugin lifecycle machinery, which can be deprecated (and eventually removed) in a later PR, which will make things much simpler. As noted in #1255, we'll want to defer app construction actions (like
add_systems
); with this PR, the collected actions can be run by turning them into an async plugin.As a followup, we should be able to use a waker and achieve the goals of #8607.
Testing
(TODO: Add plenty of tests if we decide to do this)
Showcase
Migration Guide
(TODO depending on changes)