Skip to content

Commit c6a1bf0

Browse files
authored
Add EntityMap::clear (#9291)
# Objective If you use `EntityMap` to map entities over network (https://github.com/lifescapegame/bevy_replicon) you need to reset it sometimes, but keep allocated memory for reuse. ## Solution - Add [clear](https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.clear) method. --- ## Changelog ### Added - `EntityMap::clear`.
1 parent c0510c8 commit c6a1bf0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

crates/bevy_ecs/src/entity/map_entities.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ impl EntityMap {
106106
self.map.iter().map(|(from, to)| (*from, *to))
107107
}
108108

109+
/// Clears the map, removing all entity pairs. Keeps the allocated memory for reuse.
110+
pub fn clear(&mut self) {
111+
self.map.clear();
112+
}
113+
109114
/// Creates an [`EntityMapper`] from this [`EntityMap`] and scoped to the provided [`World`], then calls the
110115
/// provided function with it. This allows one to allocate new entity references in the provided `World` that are
111116
/// guaranteed to never point at a living entity now or in the future. This functionality is useful for safely

0 commit comments

Comments
 (0)