Feature Request: Composable App update hooks
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
Access to the Bevy App is necessary for doing things like adding/removing or manipulating SubApp instances. Currently the only way (I'm aware of) to get mutable access to an App as it's running is to override the App's runner and insert your hooks in the runner's main loop. This is tricky to do as some plugins may also override the runner, and there is no way to compose this behavior. For example, the WinitPlugin overrides the App runner in ways that can't be recreated due to using private structs in the process. Additionally, overriding the runner requires you to adhere to expectations like calling `finish()` and `cleanup()` before beginning the update loop.
## What solution would you like?
Add composable post- (and potentially pre-) update hooks that can register multiple callbacks, and make these callbacks independent of the runner (calling them instead from the update() function(s) directly). For example:
```rust
fn main() {
App::new()
.register_post_update_hook(app_post_update_1)
.register_post_update_hook(app_post_update_2)
.run();
}
fn app_post_update_1(app: &mut App) {
println!("prints first after every update");
}
fn app_post_update_2(app: &mut App) {
println!("prints second after every update");
}
```
## What alternative(s) have you considered?
You can recreate this behavior using a custom runner, but as mentioned above, this does not compose well with other plugins.
Contributor guide
Assessment
This issue has not been assessed yet.