Skip to content

Commit

Permalink
Local resources don't create if already present (#745)
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 authored Oct 30, 2020
1 parent dea05e9 commit b6004e4
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 @@ -295,9 +295,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 b6004e4

Please sign in to comment.