Update entity material color #8487
-
Hello, I try to replicate the waving cube exemple from raylib with bevy (https://www.raylib.com/examples/models/loader.html?name=models_waving_cubes) Here is the definition of my bevy project : I have two component on each spawned cube :
Startup systems :
Systems:
Everything works fine apart from the update_cubes_color system. My cube are Spawn with material defined like this: How Can i update the color of each cube based on its CubeGrid coordonate in the update_cubes_color system? I know there are an other error (HSV ->HSL) but i will adress this one later as it seems much easier ;) Thanks a lot, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You need at least two system parameters to your
Now, in 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. NotesAll 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 material. |
Beta Was this translation helpful? Give feedback.
-
Thanks, it solves my issue :) Surprisingly the FPS is not very good (about 60 fps where raylib runs at about 700 fps). If someone is interested in the complete project, you can find it in : |
Beta Was this translation helpful? Give feedback.
You need at least two system parameters to your
update_cube_color
system:mut materials: ResMut<Assets<StandardMaterial>>
handles: Query<(&CubeGrid, &Handle<StandardMaterial>)>
Now, in
update_cube_color
, you need to access the&mut StandardMaterial
for your cube'sHandle
:With that, you can update the materials' color with
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…