diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index c381d424e9..b21374c25b 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -45,8 +45,9 @@ impl Plugin for WireframePlugin { ( global_color_changed.run_if(resource_changed::), wireframe_color_changed, - apply_wireframe_material, - apply_global_wireframe_material.run_if(resource_changed::), + // Run `apply_global_wireframe_material` after `apply_wireframe_material` so that the global + // wireframe setting is applied to a mesh on the same frame its wireframe marker component is removed. + (apply_wireframe_material, apply_global_wireframe_material).chain(), ), ); } @@ -137,7 +138,8 @@ fn wireframe_color_changed( } } -/// Applies or remove the wireframe material to any mesh with a [`Wireframe`] component. +/// Applies or remove the wireframe material to any mesh with a [`Wireframe`] component, and removes it +/// for any mesh with a [`NoWireframe`] component. fn apply_wireframe_material( mut commands: Commands, mut materials: ResMut>, @@ -145,10 +147,11 @@ fn apply_wireframe_material( (Entity, Option<&WireframeColor>), (With, Without>), >, + no_wireframes: Query, With>)>, mut removed_wireframes: RemovedComponents, global_material: Res, ) { - for e in removed_wireframes.read() { + for e in removed_wireframes.read().chain(no_wireframes.iter()) { if let Some(mut commands) = commands.get_entity(e) { commands.remove::>(); } @@ -171,7 +174,7 @@ fn apply_wireframe_material( type WireframeFilter = (With>, Without, Without); -/// Applies or removes a wireframe material on any mesh without a [`Wireframe`] component. +/// Applies or removes a wireframe material on any mesh without a [`Wireframe`] or [`NoWireframe`] component. fn apply_global_wireframe_material( mut commands: Commands, config: Res,