amethyst / amethyst/legion

State arguments cannot be Query-, CommandBuffer-, SubWorld, or Entity-typed

Open
#247 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.7k
Forks
140
PR merge metrics
No merged PRs in 30d

Description

Consider this example

```rust
#[system]
fn do_a_thing(#[state] target: &Entity) { ... }
```

this may be a system which is focused on working around a single entity; its starting entity is fed in during system init `do_a_thing_system(ent)`. Today, this fails with the error "error: simple systems cannot contain component references, consider using `#[system(for_each)]`" which is somewhat confusing. I am not intending to reference a component.

Of course, `Entity` is a magic component as far as `#[system]` is concerned and ends up being referenced specially when it shows up in a type. The workaround is to produce a new, distinct type `struct Target(Entity)`, take that as the state type `fn do_a_thing(#[state] target: &Target) { ... }` and then build it with that type `do_a_thing_system(Target(ent))`.

This workaround isn't too bad, and maybe is even the "ideal" way to handle this situation all together.

## Expected behavior

Either (a) the `#[state]` attribute overrides type-based dispatch or (b) at the very least the error is more clear noting how `&Entity` refs are special-cased.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.