From 6254ce5cca5ad3113c2b0baf2b9956e88d5755a2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 31 Oct 2025 15:30:00 -0500 Subject: [PATCH 1/2] documented run_system_cached #21617 --- crates/bevy_ecs/src/system/system_registry.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/bevy_ecs/src/system/system_registry.rs b/crates/bevy_ecs/src/system/system_registry.rs index 2c8b003064147..8f3367d0a2b55 100644 --- a/crates/bevy_ecs/src/system/system_registry.rs +++ b/crates/bevy_ecs/src/system/system_registry.rs @@ -500,6 +500,16 @@ impl World { /// Runs a cached system, registering it if necessary. /// + /// # Type Inference Note + /// If the system returns `()`, you may need to explicitly constrain the output + /// type for error handling: + /// + /// ```rust + /// () = world.run_system_cached(my_system)?; + /// ``` + /// + /// Without this, Rust may fail to infer the system’s output type and produce + /// a `IntoResult` inference error. /// See [`World::register_system_cached`] for more information. pub fn run_system_cached + 'static>( &mut self, @@ -509,7 +519,18 @@ impl World { } /// Runs a cached system with an input, registering it if necessary. + /// Runs a cached system, registering it if necessary. + /// + /// # Type Inference Note + /// If the system returns `()`, you may need to explicitly constrain the output + /// type for error handling: + /// + /// ```rust + /// () = world.run_system_cached(my_system)?; + /// ``` /// + /// Without this, Rust may fail to infer the system’s output type and produce + /// a `IntoResult` inference error. /// See [`World::register_system_cached`] for more information. pub fn run_system_cached_with( &mut self, From d64544d50a88ba23cb4afa230094a86d57637f56 Mon Sep 17 00:00:00 2001 From: menochs1 <83329008+menochs1@users.noreply.github.com> Date: Sat, 1 Nov 2025 00:30:28 +0000 Subject: [PATCH 2/2] SystemState ExclusiveSystemParam implementation update --- crates/bevy_ecs/src/system/function_system.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/bevy_ecs/src/system/function_system.rs b/crates/bevy_ecs/src/system/function_system.rs index 62b3597f89897..b8d8b8e21fb1d 100644 --- a/crates/bevy_ecs/src/system/function_system.rs +++ b/crates/bevy_ecs/src/system/function_system.rs @@ -91,6 +91,25 @@ impl SystemMeta { #[inline] pub fn set_non_send(&mut self) { self.flags |= SystemStateFlags::NON_SEND; + /// Alternatively, for exclusive systems the ECS can automatically cache a + /// `SystemState` for you. The trait [`ExclusiveSystemParam`] is implemented for + /// `&'a mut SystemState

`, so if your function is an exclusive system + /// (takes `&mut World` as its first parameter) you can accept + /// `&mut SystemState<...>` directly and the ECS will initialize and persist it + /// across invocations. Example: + /// ``` + /// # use bevy_ecs::prelude::*; + /// # use bevy_ecs::system::SystemState; + /// # + /// # #[derive(Message)] + /// # struct MyMessage; + /// fn exclusive_system(world: &mut World, system_state: &mut SystemState>) { + /// let mut message_reader = system_state.get_mut(world); + /// for message in message_reader.read() { + /// println!("Hello World!"); + /// } + /// } + /// ``` } /// Returns true if the system has deferred [`SystemParam`]'s