amethyst/legion

Unnecessary error in #[system] validation

Schmavery opened this issue · 0 comments

Was playing with legion (3.1.0) and trying to copy various examples of systems, but kept running into the "simple systems cannot contain component references" error.

return Err(Error::Message("simple systems cannot contain component references, consider using `#[system(for_each)]`".to_string()));

I eventually realized that I needed to import the SubWorld rather than qualifying it. I was writing this:

#[system]
#[read_component(usize)]
#[write_component(bool)]
fn run_query(world: &mut world::SubWorld) {
    let mut query = <(&usize, &mut bool)>::query();
    for (a, b) in query.iter_mut(world) {
        println!("{} {}", a, b);
    }
}

which is an example from the docs with the world:: added before SubWorld, and then I got the error above. Pretty new to rust so I expected this to be equivalent to importing and then using it.

Importing it is a fine workaround for me but I thought I'd mention it case it helps someone! Thanks!

Edit: looked a bit more at the code and maybe it's just a matter of adding the "world::SubWorld" case here? I was importing legion as use legion::* as it says in the docs in a few places, which made my editor automatically suggest the qualification relative to "world" rather than "legion", I guess. Either that or expose SubWorld from legion::* I guess (didn't seem like it was).

|| is_type(&ty.elem, &["legion", "world", "SubWorld"]) =>