Skip to content

Commit bc5cd93

Browse files
committed
Local resources don't create if already present
Local<T> will no longer insert the inner resource if it already exists.
1 parent a592ef0 commit bc5cd93

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

crates/bevy_ecs/src/resource/resource_query.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,13 @@ impl<'a, T: Resource + FromResources> ResourceQuery for Local<'a, T> {
297297
type Fetch = FetchResourceLocalMut<T>;
298298

299299
fn initialize(resources: &mut Resources, id: Option<SystemId>) {
300-
let value = T::from_resources(resources);
301300
let id = id.expect("Local<T> resources can only be used by systems");
302-
resources.insert_local(id, value);
301+
302+
// Only add the local resource if it doesn't already exist for this system
303+
if resources.get_local::<T>(id).is_none() {
304+
let value = T::from_resources(resources);
305+
resources.insert_local(id, value);
306+
}
303307
}
304308
}
305309

0 commit comments

Comments
 (0)