From bc5cd939572b5ec64b8c5ac7a144b4bcd9a91a6d Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 28 Oct 2020 17:15:44 -0700 Subject: [PATCH] Local resources don't create if already present Local will no longer insert the inner resource if it already exists. --- crates/bevy_ecs/src/resource/resource_query.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/resource/resource_query.rs b/crates/bevy_ecs/src/resource/resource_query.rs index 267f45a8a09e8..92742343b47c6 100644 --- a/crates/bevy_ecs/src/resource/resource_query.rs +++ b/crates/bevy_ecs/src/resource/resource_query.rs @@ -297,9 +297,13 @@ impl<'a, T: Resource + FromResources> ResourceQuery for Local<'a, T> { type Fetch = FetchResourceLocalMut; fn initialize(resources: &mut Resources, id: Option) { - let value = T::from_resources(resources); let id = id.expect("Local resources can only be used by systems"); - resources.insert_local(id, value); + + // Only add the local resource if it doesn't already exist for this system + if resources.get_local::(id).is_none() { + let value = T::from_resources(resources); + resources.insert_local(id, value); + } } }