Skip to content

Replace startup systems with a built-in state enum that handles resource cleanup #5437

@alice-i-cecile

Description

@alice-i-cecile

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AppBevy apps and pluginsA-AssetsLoad files from disk to use for things like images, models, and soundsA-ECSEntities, components, systems, and eventsA-StatesApp-level states machinesC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useX-ControversialThere is active debate or serious implications around merging this PR

    Type

    No type

    Projects

    Status

    Needs Implementation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions