Skip to content

Commit baae97d

Browse files
committed
iter_mut on Assets: send modified event only when asset is iterated over (#3565)
# Objective - `Assets<T>::iter_mut` sends `Modified` event for all assets first, then returns the iterator - This means that events could be sent for assets that would not have been mutated if iteration was stopped before ## Solution - Send `Modified` event when assets are iterated over. Co-authored-by: François <[email protected]>
1 parent 6c95b58 commit baae97d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crates/bevy_asset/src/assets.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ impl<T: Asset> Assets<T> {
186186

187187
/// Get a mutable iterator over all assets in the collection.
188188
pub fn iter_mut(&mut self) -> impl Iterator<Item = (HandleId, &mut T)> {
189-
for id in self.assets.keys() {
189+
self.assets.iter_mut().map(|(k, v)| {
190190
self.events.send(AssetEvent::Modified {
191-
handle: Handle::weak(*id),
191+
handle: Handle::weak(*k),
192192
});
193-
}
194-
self.assets.iter_mut().map(|(k, v)| (*k, v))
193+
(*k, v)
194+
})
195195
}
196196

197197
/// Get an iterator over all [`HandleId`]'s in the collection.

0 commit comments

Comments
 (0)