Skip to content

Commit

Permalink
Add an example of configuring systems
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Feb 1, 2022
1 parent e2f3f67 commit 7c75a0c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,22 @@ impl<'w, 's> SystemParamFetch<'w, 's> for CommandQueue {
/// // Note how the read local is still 0 due to the locals not being shared.
/// assert_eq!(read_system.run((), world), 0);
/// ```
///
/// N.B. A [`Local`]s value cannot be read or written to outside of the containing system.
/// To add configuration to a system, convert a capturing closure into the system instead:
///
/// ```
/// # use bevy_ecs::prelude::*;
/// struct Config(u32);
/// struct Myu32Wrapper(u32);
/// fn reset_to(value: Config) -> impl FnMut(ResMut<Myu32Wrapper>) {
/// move |mut val| val.0 = value.0
/// }
///
/// // .add_system(reset_to(my_config))
/// # reset_to(Config(10)).system();
/// ```

pub struct Local<'a, T: Resource>(&'a mut T);

// SAFE: Local only accesses internal state
Expand Down

0 comments on commit 7c75a0c

Please sign in to comment.