Skip to content

Teardown/exit systems #7067

@Testare

Description

@Testare

What problem does this solve or what need does it fill?

We have systems that run once at the start of an App, the startup systems. What is missing is the opposite: Systems that run once at the end of the program. A specific example of this would be an app that changes terminal state to raw mode at the start, but needs to change it back at the end. Or a game that saves on exit.

What solution would you like?

I think it would be nice if there were the ability to add exit systems to the App in a similar fashion as the way we add startup systems to the App.

What alternative(s) have you considered?

You can currently get pretty much the same behavior by having a system with EventReader. Unfortunately, this behavior depends heavily on system scheduling, as once AppExit is written, and game loop completes, the system exits. To run this after the user exits the window, for example, I had to look up the WindowsPlugin and find out that it added the "exit_on_all_closed" system in the CoreStage::PostUpdate stage. Then I had to add the exit system to the CoreStage::Last stage.

So, while this might not be the highest priority since this functionality isn't /necessary/ for anything, it would be nice if there was a simpler way to do it where I wasn't worried that I was going to miss the AppExit event being emitted.

Additional context

I had first asked about this on reddit when trying to figure out a solution to a specific problem of mine: https://www.reddit.com/r/bevy/comments/zzjex9

I've discovered the solution provided, but it has been pointed out this might be a good thing to create an issue for on Github, either to implement exit systems for the App or at the very least provide a little more information on the AppExit page for how to create these exit systems within the current framework.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AppBevy apps and pluginsC-DocsAn addition or correction to our documentationC-FeatureA new feature, making something new possibleS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-Needs-SMEThis type of work requires an SME to approve it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions