Skip to content

Update entity material color #8487

Answered by nicopap
AlexandreFleutelot asked this question in Q&A
Discussion options

You must be logged in to vote

You need at least two system parameters to your update_cube_color system:

  1. mut materials: ResMut<Assets<StandardMaterial>>
  2. handles: Query<(&CubeGrid, &Handle<StandardMaterial>)>

Now, in update_cube_color, you need to access the &mut StandardMaterial for your cube's Handle:

let material = materials.get_mut(cube_handle).unwrap();

With that, you can update the materials' color with

material.base_color = color_from_grid(cube_grid);

You should be done.

Notes

All your cubes need to have a distinct material for this approach to work, otherwise you would just be updating the same material multiple times. As you described your current program, it seems that each cube does indeed have a distinct m…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by AlexandreFleutelot
Comment options

You must be logged in to vote
1 reply
@NiklasEi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
A-Rendering Drawing game state to the screen A-Assets Load files from disk to use for things like images, models, and sounds
3 participants