Skip to content

Commit 7c75a0c

Browse files
committed
Add an example of configuring systems
1 parent e2f3f67 commit 7c75a0c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,22 @@ impl<'w, 's> SystemParamFetch<'w, 's> for CommandQueue {
520520
/// // Note how the read local is still 0 due to the locals not being shared.
521521
/// assert_eq!(read_system.run((), world), 0);
522522
/// ```
523+
///
524+
/// N.B. A [`Local`]s value cannot be read or written to outside of the containing system.
525+
/// To add configuration to a system, convert a capturing closure into the system instead:
526+
///
527+
/// ```
528+
/// # use bevy_ecs::prelude::*;
529+
/// struct Config(u32);
530+
/// struct Myu32Wrapper(u32);
531+
/// fn reset_to(value: Config) -> impl FnMut(ResMut<Myu32Wrapper>) {
532+
/// move |mut val| val.0 = value.0
533+
/// }
534+
///
535+
/// // .add_system(reset_to(my_config))
536+
/// # reset_to(Config(10)).system();
537+
/// ```
538+
523539
pub struct Local<'a, T: Resource>(&'a mut T);
524540

525541
// SAFE: Local only accesses internal state

0 commit comments

Comments
 (0)