Tainted\\Coders

Plugin organization

Bevy version: 0.16Last updated:

We should structure our game to roughly follow the rule of 1 plugin per file.

Write your plugins in a way that has the least friction, that usually means prefering the simpler interface of a function instead of impl Plugin unless you need the extra functionality:

use bevy::prelude::*;

pub(super) fn plugin(app: &mut App) {
    app.add_systems(Update, (move_player, move_enemies));
}

To further keep logic out of main and inside your lib (which can make testing easier) you can have a top most plugin that sets everything up.

This lets you keep your main.rs file clean:

// src/main.rs
use bevy::prelude::*;

use starter::AppPlugin;

fn main() {
  App::new().add_plugins(AppPlugin).run();
}

Now when you go to test your game, you are not recreating logic inside main you can simply load your AppPlugin inside a new App.