Skip to content

Change colour on a StandardMaterial #6907

Answered by wilk10
joebain asked this question in Q&A
Discussion options

You must be logged in to vote

The first setup doesn't work any more because now the entity with the PbrBundle is a child of Enemy, whose Entity is stored in the Children component. So to access the material handle, you now need two queries:

fn change_material(
    enemies: Query<&Children, With<Enemy>>,
    mut standard_materials: Query<&mut Handle<StandardMaterial>> ,
) { 
    for children_of_enemy in enemies.iter() {
        for child in children_of_enemy.iter() {
            if let Ok(handle) = standard_materials.get_mut(child) {
                // etc
            }
        }
    }
}

In the second case it doesn't work because you need to substitute the Handle, not mutate the colour. If you change the colour, you ne…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@joebain
Comment options

@tim-blackbird
Comment options

Answer selected by joebain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants