Skip to content

How to pass data that is going to be used in a system to a plugin? #2517

Answered by cart
IceSentry asked this question in Q&A
Discussion options

You must be logged in to vote

We currently recommend (and use internally) the "plugin settings as resource" pattern. For example, the official LogPlugin looks like this:

struct LogPlugin;

pub struct LogSettings {
    pub filter: String,
    pub level: Level,
}

impl Plugin for LogPlugin {
    fn build(&self, app: &mut AppBuilder) {
        let settings = app.world_mut().get_resource_or_insert_with(LogSettings::default);
        // initialize plugin
    }
}

We encourage this pattern for a few reasons:

  1. Plays nicely with plugin groups
  2. Enables using ECS change detection to respond to respond to settings changes at runtime
  3. We ultimately might add "plugin lifecycles", which would remove the ability to directly construct P…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants