#Unable to use Query for Nested Bundle

4 messages · Page 1 of 1 (latest)

calm viper
#

I want to access a nested MaterialMesh2dBundle for its transform component in order to change the position of a ball on screen. When I try to use a query it throws: error[E0277]: the trait bound MaterialMesh2dBundlebevy::prelude::ColorMaterial: bevy::prelude::Component is not satisfied. I am able to successfully access Position and Velocity.

Should I be accessing the transform independently, despite it being nested in my Ball and MaterialMesh2DBundle bundle? Whats going on here?

fn move_ball(mut query: Query<(&mut Position, &Velocity, &MaterialMesh2dBundle<ColorMaterial>)>,){
    for (mut position, velocity, mesh2dbundle) in query.iter_mut() {
        position.x = position.x + velocity.x;
        position.y = position.y + velocity.y;

        mesh2dbundle.transform = Transform::from_xyz(5.0, 6.0, 7.0);
    }
    println!("moved da ball");
}
delicate perch
#

You should not use a bundle in a query. This is what the docs say:

Importantly, bundles are only their constituent set of components. You should not use bundles as a unit of behavior. The behavior of your app can only be considered in terms of components, as systems, which drive the behavior of a bevy application, operate on combinations of components.

So you should simply use ColorMaterial directly in the query, as a component. Does that work?

calm viper
#

Very helpful!

#

and yes i think it did, but i am changing the transform incorrectly