plugin_group/
plugin_group.rs

1//! Demonstrates the creation and registration of a custom plugin group.
2//! [`PluginGroup`]s are a way to group sets of plugins that should be registered together.
3
4use bevy::{app::PluginGroupBuilder, prelude::*};
5
6fn main() {
7    App::new()
8        .add_plugins((
9            // Two PluginGroups that are included with bevy are DefaultPlugins and MinimalPlugins
10            DefaultPlugins,
11            // Adding a plugin group adds all plugins in the group by default
12            HelloWorldPlugins,
13        ))
14        // You can also modify a PluginGroup (such as disabling plugins) like this:
15        // .add_plugins(
16        //     HelloWorldPlugins
17        //         .build()
18        //         .disable::<PrintWorldPlugin>()
19        //         .add_before::<PrintHelloPlugin>(
20        //             bevy::diagnostic::LogDiagnosticsPlugin::default(),
21        //         ),
22        // )
23        .run();
24}
25
26/// A group of plugins that produce the "hello world" behavior
27pub struct HelloWorldPlugins;
28
29impl PluginGroup for HelloWorldPlugins {
30    fn build(self) -> PluginGroupBuilder {
31        PluginGroupBuilder::start::<Self>()
32            .add(PrintHelloPlugin)
33            .add(PrintWorldPlugin)
34    }
35}
36
37struct PrintHelloPlugin;
38
39impl Plugin for PrintHelloPlugin {
40    fn build(&self, app: &mut App) {
41        app.add_systems(Update, print_hello_system);
42    }
43}
44
45fn print_hello_system() {
46    info!("hello");
47}
48
49struct PrintWorldPlugin;
50
51impl Plugin for PrintWorldPlugin {
52    fn build(&self, app: &mut App) {
53        app.add_systems(Update, print_world_system);
54    }
55}
56
57fn print_world_system() {
58    info!("world");
59}