Skip to content

Commit d0d3874

Browse files
committed
Handle materials being locked when setting wireframe colors.
1 parent 4e544f8 commit d0d3874

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

crates/bevy_pbr/src/wireframe.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Plugin for WireframePlugin {
4141
.add_systems(
4242
Update,
4343
(
44-
global_color_changed.run_if(resource_changed::<WireframeConfig>),
44+
global_color_changed,
4545
wireframe_color_changed,
4646
// Run `apply_global_wireframe_material` after `apply_wireframe_material` so that the global
4747
// wireframe setting is applied to a mesh on the same frame its wireframe marker component is removed.
@@ -115,12 +115,22 @@ fn setup_global_wireframe_material(
115115

116116
/// Updates the wireframe material of all entities without a [`WireframeColor`] or without a [`Wireframe`] component
117117
fn global_color_changed(
118+
mut desynced: Local<bool>,
118119
config: Res<WireframeConfig>,
119120
mut materials: ResMut<Assets<WireframeMaterial>>,
120121
global_material: Res<GlobalWireframeMaterial>,
121122
) {
122-
if let Some(global_material) = materials.get_mut(&global_material.handle) {
123+
if config.is_changed() {
124+
*desynced = true;
125+
}
126+
if !*desynced {
127+
// There's been no change, so bail out early.
128+
return;
129+
}
130+
if let Ok(global_material) = materials.get_mut(&global_material.handle) {
123131
global_material.color = config.default_color.into();
132+
// Clear the desynced flag to mark that we don't need to rerun this system.
133+
*desynced = false;
124134
}
125135
}
126136

crates/bevy_sprite/src/mesh2d/wireframe2d.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Plugin for Wireframe2dPlugin {
4141
.add_systems(
4242
Update,
4343
(
44-
global_color_changed.run_if(resource_changed::<Wireframe2dConfig>),
44+
global_color_changed,
4545
wireframe_color_changed,
4646
// Run `apply_global_wireframe_material` after `apply_wireframe_material` so that the global
4747
// wireframe setting is applied to a mesh on the same frame its wireframe marker component is removed.
@@ -111,12 +111,22 @@ fn setup_global_wireframe_material(
111111

112112
/// Updates the wireframe material of all entities without a [`Wireframe2dColor`] or without a [`Wireframe2d`] component
113113
fn global_color_changed(
114+
mut desynced: Local<bool>,
114115
config: Res<Wireframe2dConfig>,
115116
mut materials: ResMut<Assets<Wireframe2dMaterial>>,
116117
global_material: Res<GlobalWireframe2dMaterial>,
117118
) {
118-
if let Some(global_material) = materials.get_mut(&global_material.handle) {
119+
if config.is_changed() {
120+
*desynced = true;
121+
}
122+
if !*desynced {
123+
// There's been no change, so bail out early.
124+
return;
125+
}
126+
if let Ok(global_material) = materials.get_mut(&global_material.handle) {
119127
global_material.color = config.default_color.into();
128+
// Clear the desynced flag to mark that we don't need to rerun this system.
129+
*desynced = false;
120130
}
121131
}
122132

0 commit comments

Comments
 (0)