diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index 1ac3930a0a..34ffb930db 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -863,6 +863,9 @@ pub fn specialize_material_meshes( .or_default(); for (_, visible_entity) in visible_entities.iter::() { + let Some(material_asset_id) = render_material_instances.get(visible_entity) else { + continue; + }; let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap(); let last_specialized_tick = view_specialized_material_pipeline_cache .get(visible_entity) @@ -874,9 +877,6 @@ pub fn specialize_material_meshes( if !needs_specialization { continue; } - let Some(material_asset_id) = render_material_instances.get(visible_entity) else { - continue; - }; let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity) else { continue; diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index ea60f42667..724e96b429 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -962,6 +962,9 @@ pub fn specialize_prepass_material_meshes( .or_default(); for (_, visible_entity) in visible_entities.iter::() { + let Some(material_asset_id) = render_material_instances.get(visible_entity) else { + continue; + }; let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap(); let last_specialized_tick = view_specialized_material_pipeline_cache .get(visible_entity) @@ -973,10 +976,6 @@ pub fn specialize_prepass_material_meshes( if !needs_specialization { continue; } - - let Some(material_asset_id) = render_material_instances.get(visible_entity) else { - continue; - }; let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(*visible_entity) else { continue; diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 6f3216d896..a770a83bca 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1809,6 +1809,9 @@ pub fn specialize_shadows( .or_default(); for (_, visible_entity) in visible_entities.iter().copied() { + let Some(material_asset_id) = render_material_instances.get(&visible_entity) else { + continue; + }; let entity_tick = entity_specialization_ticks.get(&visible_entity).unwrap(); let last_specialized_tick = view_specialized_material_pipeline_cache .get(&visible_entity) @@ -1820,7 +1823,9 @@ pub fn specialize_shadows( if !needs_specialization { continue; } - + let Some(material) = render_materials.get(*material_asset_id) else { + continue; + }; let Some(mesh_instance) = render_mesh_instances.render_mesh_queue_data(visible_entity) else { @@ -1832,12 +1837,6 @@ pub fn specialize_shadows( { continue; } - let Some(material_asset_id) = render_material_instances.get(&visible_entity) else { - continue; - }; - let Some(material) = render_materials.get(*material_asset_id) else { - continue; - }; let Some(material_bind_group) = material_bind_group_allocator.get(material.binding.group) else { diff --git a/crates/bevy_sprite/src/mesh2d/material.rs b/crates/bevy_sprite/src/mesh2d/material.rs index 81ad7a9e3e..ce2803b261 100644 --- a/crates/bevy_sprite/src/mesh2d/material.rs +++ b/crates/bevy_sprite/src/mesh2d/material.rs @@ -698,6 +698,9 @@ pub fn specialize_material2d_meshes( .or_default(); for (_, visible_entity) in visible_entities.iter::() { + let Some(material_asset_id) = render_material_instances.get(visible_entity) else { + continue; + }; let entity_tick = entity_specialization_ticks.get(visible_entity).unwrap(); let last_specialized_tick = view_specialized_material_pipeline_cache .get(visible_entity) @@ -709,10 +712,6 @@ pub fn specialize_material2d_meshes( if !needs_specialization { continue; } - - let Some(material_asset_id) = render_material_instances.get(visible_entity) else { - continue; - }; let Some(mesh_instance) = render_mesh_instances.get_mut(visible_entity) else { continue; };