diff --git a/crates/bevy_render/src/picking.rs b/crates/bevy_render/src/picking.rs index df1ef091509348..082007e89e7480 100644 --- a/crates/bevy_render/src/picking.rs +++ b/crates/bevy_render/src/picking.rs @@ -139,19 +139,17 @@ impl GpuPickingCamera { } // TODO This is currently a constant, but could be user configurable - let entity = match MESH_ID_TEXTURE_FORMAT { + let texture_bytes = &self.data.mesh_id_buffer[start..end]; + let index = match MESH_ID_TEXTURE_FORMAT { TextureFormat::R16Uint => { - let index = - u16::from_ne_bytes(self.data.mesh_id_buffer[start..end].try_into().ok()?); - self.data.visible_mesh_entities[index as usize] + u16::from_ne_bytes(texture_bytes.try_into().ok()?) as usize } TextureFormat::R32Uint => { - let index = - u32::from_ne_bytes(self.data.mesh_id_buffer[start..end].try_into().ok()?); - self.data.visible_mesh_entities[index as usize] + u32::from_ne_bytes(texture_bytes.try_into().ok()?) as usize } _ => panic!("Unsupported mesh id texture format"), }; + let entity = self.data.visible_mesh_entities[index]; if entity != Entity::PLACEHOLDER { Some(entity)