App Builder (main function)

Relevant official examples: ecs_guide, hello_world, empty, empty_defaults, headless.


To enter the bevy runtime, you need to configure an App, composed of all the systems, plugins, event types, and resources, that you want to use.

Everything must be registered in the App, or it will not work.

Component types and local resources do not need to be registered.

Resources can also be created later, using Commands.

You also need to add Bevy's built-in functionality: either DefaultPlugins if you are making a full game/app, or MinimalPlugins for something like a headless server.

fn main() {
    App::build()
        // bevy
        .add_plugins(DefaultPlugins)

        // resources:
        .insert_resource(StartingLevel(3))
        // if it implements `Default` or `FromWorld`
        .init_resource::<MyFancyResource>()

        // events:
        .add_event::<LevelUpEvent>()

        // systems to run once at startup:
        .add_startup_system(spawn_player.system())

        // systems to run each frame:
        .add_system(player_level_up.system())
        .add_system(debug_levelups.system())
        .add_system(debug_stats_change.system())
        // ...

        // launch the app!
        .run();
}