Replace startup systems with a built-in state enum that handles resource cleanup
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 4d 8m
- Merged PRs (30d)
- 147
Description
# Problem
1. Startup systems are largely special-cased, they rely on custom stage implementations and it's quite hard to teach the model.
2. It is challenging to ensure appropriate cleanup of resources on `AppExit`: we must listen for the event and carefully time the resources.
## Proposed solution
```rust
/// A built-in game state that controls app control flow
///
/// This is enabled by default, and user systems are added to the `Main` variant by default
enum AppState {
Startup,
Main,
Exit,
}
```
This allows us to use standard on-enter, on-exit and state transition methods to control things like asset loading, cleanup, pausing the game, autosaving on exit and so on.
## Extensions
We could add an explicit asset loading state as well. This may work well, but could be controversial.
## Context
Discussed with @IceSentry on [Discord](https://discord.com/channels/691052431525675048/1000497773474496544/1000500300127408168) after trying to help a user ensure data is cleaned up correctly.
This builds on but does not require the patterns espoused by the [Stageless RFC}(https://github.com/bevyengine/rfcs/pull/45).
Would address #1353. If we were to implement this, we would likely want to have a more robust event strategy by default, to ensure that gameplay events do not get lost during a pause.
Contributor guide
Assessment
This issue has not been assessed yet.