diff --git a/crates/bevy_asset/src/asset_server.rs b/crates/bevy_asset/src/asset_server.rs index 097b96541b5805..ab1f4ed9ec4e87 100644 --- a/crates/bevy_asset/src/asset_server.rs +++ b/crates/bevy_asset/src/asset_server.rs @@ -360,14 +360,11 @@ impl AssetServer { .detach(); let handle_id = asset_path.get_id().into(); - - // check if the `handle_id` exists first to avoid unnecessary `write()` calls. - if !self.server.handle_to_path.read().contains_key(&handle_id) { - self.server - .handle_to_path - .write() - .insert(handle_id, asset_path.to_owned()); - } + self.server + .handle_to_path + .write() + .entry(handle_id) + .or_insert_with(|| asset_path.to_owned()); asset_path.into() }