Tainted \\ Coders

Run a plugin conditionally

Last updated:

Plugins are statically configured when your App is built so there is no real way to add or remove them from your app during runtime.

You can however use run conditions or some other logic to have them run when your game is in a certain state.

pub struct GamePlugin;

impl Plugin for GamePlugin {
    fn build(&self, app: &mut App) {
        app
        .add_systems(
            Update,
            system_a
                .run_if(in_state(GameState::MainMenu))
        )
        .add_systems(
            Update,
            system_b
                .run_if(in_state(GameState::Game))
        );
    }
}