Skip to content

Commit 1263382

Browse files
committed
Make headless_defaults example actually headless
Fixes #5260
1 parent 518408d commit 1263382

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/app/headless_defaults.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
//! An application that runs with default plugins, but without an actual renderer.
22
//! This can be very useful for integration tests or CI.
33
4-
use bevy::{prelude::*, render::settings::WgpuSettings};
4+
use bevy::{app::AppExit, prelude::*, render::settings::WgpuSettings, window::WindowSettings};
55

66
fn main() {
77
App::new()
88
.insert_resource(WgpuSettings {
99
backends: None,
1010
..default()
1111
})
12+
.insert_resource(WindowSettings {
13+
add_primary_window: false,
14+
exit_on_all_closed: false,
15+
..default()
16+
})
1217
.add_plugins(DefaultPlugins)
18+
.add_system(do_something)
1319
.run();
1420
}
21+
22+
// Normally Bevy exits when all windows are closed.
23+
//
24+
// When running in headless mode there are no windows so
25+
// you must manually send an [`bevy::app::AppExit`] event.
26+
fn do_something(mut app_exit_events: EventWriter<AppExit>) {
27+
info!("Successfully ran! Exiting...");
28+
app_exit_events.send(AppExit);
29+
}

0 commit comments

Comments
 (0)