From 7c75a0cfdd6335bf409462a007e390d0d7239ada Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 1 Feb 2022 13:02:07 +0000 Subject: [PATCH] Add an example of configuring systems --- crates/bevy_ecs/src/system/system_param.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 213fbab26a9c4d..b4d3e1b2e7d656 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -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) { +/// 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