Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy ECS readme: not working example due to missing #[derive(Component)] #3005

Closed
QQism opened this issue Oct 22, 2021 · 2 comments
Closed
Labels
C-Docs An addition or correction to our documentation D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@QQism
Copy link

QQism commented Oct 22, 2021

Hi everyone,

I'm tinkering with bevy_ecs and just realized that its README is not up-to-date with the recent change making #[derive(Component)] mandatory for all component structs.

Specifically

struct Velocity {
x: f32,
y: f32,
}
struct Position {
x: f32,
y: f32,
}
// This system moves each entity with a Position and Velocity component
fn movement(query: Query<(&mut Position, &Velocity)>) {
for (mut position, velocity) in query.iter_mut() {
position.x += velocity.x;
position.y += velocity.y;
}
}
fn main() {
// Create a new empty World to hold our Entities and Components
let mut world = World::new();
// Spawn an entity with Position and Velocity components
world.spawn()
.insert(Position { x: 0.0, y: 0.0 })
.insert(Velocity { x: 1.0, y: 0.0 });
// Create a new Schedule, which defines an execution strategy for Systems
let mut schedule = Schedule::default();

Attempt to run the example would result in errors as below

the trait `bevy_ecs::component::Component` is not implemented for `Position`
the trait `bevy_ecs::component::Component` is not implemented for `Velocity`

Also, it could be worth it to mention that components are Rust structs but also need to implement bevy_ecs's Component trait.

Components are normal Rust structs. They are data stored in a `World` and specific instances of Components correlate to Entities.
```rust
struct Position { x: f32, y: f32 }
```

@QQism QQism added C-Docs An addition or correction to our documentation S-Needs-Triage This issue needs to be labelled labels Oct 22, 2021
@DJMcNab
Copy link
Member

DJMcNab commented Oct 22, 2021

Indeed, thanks for pointing it out

The license badge is also outdated

@mockersf
Copy link
Member

#2575 should help avoid this issue as code blocks in readme will be tested

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy and removed S-Needs-Triage This issue needs to be labelled labels Oct 22, 2021
jamesbeilby added a commit to jamesbeilby/bevy that referenced this issue Nov 10, 2021
@bors bors bot closed this as completed in e018ac8 Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Docs An addition or correction to our documentation D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
4 participants