Skip to content

Commit

Permalink
Local resources don't create if already present
Browse files Browse the repository at this point in the history
Local<T> will no longer insert the inner resource if it already exists.
  • Loading branch information
Jerald committed Oct 30, 2020
1 parent a592ef0 commit bc5cd93
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/bevy_ecs/src/resource/resource_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,13 @@ impl<'a, T: Resource + FromResources> ResourceQuery for Local<'a, T> {
type Fetch = FetchResourceLocalMut<T>;

fn initialize(resources: &mut Resources, id: Option<SystemId>) {
let value = T::from_resources(resources);
let id = id.expect("Local<T> 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::<T>(id).is_none() {
let value = T::from_resources(resources);
resources.insert_local(id, value);
}
}
}

Expand Down

0 comments on commit bc5cd93

Please sign in to comment.