Skip to content

Frequently Asked Questions

Thomas Schaller edited this page Nov 2, 2017 · 6 revisions

Overview

How to join over components without requiring all of them?

Answer: Only join the required ones plus the Entities and use Storage::get to retrieve the optional ones.

type SystemData = (Entities<'a>, ReadStorage<'a, Required>, ReadStorage<'a, Optional>);

fn run(&mut self, (ent, req, opt): Self::SystemData) {
    for (e, req) in (&*ent, &req).join() {
        let opt: Option<&Optional> = opt.get(e);

        // Use components here
    }
}
Clone this wiki locally