Skip to main content

return_after_run/
return_after_run.rs

1//! Shows how to return to the calling function after a windowed Bevy app has exited.
2//!
3//! In windowed *Bevy* applications, executing code below a call to `App::run()` is
4//! not recommended because:
5//! - `App::run()` will never return on iOS and Web.
6//! - It is not possible to recreate a window after the event loop has been terminated.
7
8use bevy::prelude::*;
9
10fn main() {
11    println!("Running Bevy App");
12    App::new()
13        .add_plugins(DefaultPlugins.set(WindowPlugin {
14            primary_window: Some(Window {
15                title: "Close the window to return to the main function".into(),
16                ..default()
17            }),
18            ..default()
19        }))
20        .add_systems(Update, system)
21        .run();
22    println!("Bevy App has exited. We are back in our main function.");
23}
24
25fn system() {
26    info!("Logging from Bevy App");
27}