From 6fee6fe8278afa1f36669d208806e8a0665be691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20S=C3=B8holm?= Date: Wed, 4 Jun 2025 18:34:27 +0200 Subject: [PATCH] Add get_mut_untracked to Assets (#19487) # Objective Fixes #13104 ## Solution Add a `get_mut_untracked` method to `Assets` --- crates/bevy_asset/src/assets.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 9fa8eb4381..6e5b488ee0 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -437,6 +437,18 @@ impl Assets { result } + /// Retrieves a mutable reference to the [`Asset`] with the given `id`, if it exists. + /// + /// This is the same as [`Assets::get_mut`] except it doesn't emit [`AssetEvent::Modified`]. + #[inline] + pub fn get_mut_untracked(&mut self, id: impl Into>) -> Option<&mut A> { + let id: AssetId = id.into(); + match id { + AssetId::Index { index, .. } => self.dense_storage.get_mut(index), + AssetId::Uuid { uuid } => self.hash_map.get_mut(&uuid), + } + } + /// Removes (and returns) the [`Asset`] with the given `id`, if it exists. /// Note that this supports anything that implements `Into>`, which includes [`Handle`] and [`AssetId`]. pub fn remove(&mut self, id: impl Into>) -> Option { @@ -450,6 +462,8 @@ impl Assets { /// Removes (and returns) the [`Asset`] with the given `id`, if it exists. This skips emitting [`AssetEvent::Removed`]. /// Note that this supports anything that implements `Into>`, which includes [`Handle`] and [`AssetId`]. + /// + /// This is the same as [`Assets::remove`] except it doesn't emit [`AssetEvent::Removed`]. pub fn remove_untracked(&mut self, id: impl Into>) -> Option { let id: AssetId = id.into(); self.duplicate_handles.remove(&id);