Skip to content

Commit 544b6df

Browse files
author
KDecay
committed
Change default ColorMaterial color to white (#3981)
# Context I wanted to add a `texture` to my `ColorMaterial` without explicitly adding a `color`. To do this I used `..Default::default()` which in turn gave me unexpected results. I was expecting that my texture would render without any color modifications, but to my surprise it got rendered in a purple tint (`Color::rgb(1.0, 0.0, 1.0)`). To fix this I had to explicitly define the `color` using `color: Color::WHITE`. ## What I wanted to use ```rust commands .spawn_bundle(MaterialMesh2dBundle { mesh: mesh_handle.clone().into(), transform: Transform::default().with_scale(Vec3::splat(8.)), material: materials.add(ColorMaterial { texture: Some(texture_handle.clone()), ..Default::default() // here }), ..Default::default() }) ``` ![image](https://user-images.githubusercontent.com/75334794/154765141-4a8161ce-4ec8-4687-b7d5-18ddf1b58660.png) ## What I had to use instead ```rust commands .spawn_bundle(MaterialMesh2dBundle { mesh: mesh_handle.clone().into(), transform: Transform::default().with_scale(Vec3::splat(8.)), material: materials.add(ColorMaterial { texture: Some(texture_handle.clone()), color: Color::WHITE, // here }), ..Default::default() }) ``` ![image](https://user-images.githubusercontent.com/75334794/154765225-f1508b41-9d5b-4f0c-af7b-e89c1a82d85b.png)
1 parent 98938a8 commit 544b6df

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/bevy_sprite/src/mesh2d/color_material.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct ColorMaterial {
5858
impl Default for ColorMaterial {
5959
fn default() -> Self {
6060
ColorMaterial {
61-
color: Color::rgb(1.0, 0.0, 1.0),
61+
color: Color::WHITE,
6262
texture: None,
6363
}
6464
}
@@ -77,7 +77,7 @@ impl From<Handle<Image>> for ColorMaterial {
7777
fn from(texture: Handle<Image>) -> Self {
7878
ColorMaterial {
7979
texture: Some(texture),
80-
color: Color::WHITE,
80+
..Default::default()
8181
}
8282
}
8383
}

0 commit comments

Comments
 (0)