Skip to content

Commit 1f05e1e

Browse files
Add 'World::run_system_with_input' function + allow World::run_system to get system output (#10380)
# Objective Allows chained systems taking an `In<_>` input parameter to be run as one-shot systems. This API was mentioned in #8963. In addition, `run_system(_with_input)` returns the system output, for any `'static` output type. ## Solution A new function, `World::run_system_with_input` allows a `SystemId<I, O>` to be run by providing an `I` value as input and producing `O` as an output. `SystemId<I, O>` is now generic over the input type `I` and output type `O`, along with the related functions and types `RegisteredSystem`, `RemovedSystem`, `register_system`, `remove_system`, and `RegisteredSystemError`. These default to `()`, preserving the existing API, for all of the public types. --- ## Changelog - Added `World::run_system_with_input` function to allow one-shot systems that take `In<_>` input parameters - Changed `World::run_system` and `World::register_system` to support systems with return types beyond `()` - Added `Commands::run_system_with_input` command that schedules a one-shot system with an `In<_>` input parameter
1 parent bad55c1 commit 1f05e1e

File tree

2 files changed

+308
-38
lines changed

2 files changed

+308
-38
lines changed

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
self as bevy_ecs,
66
bundle::Bundle,
77
entity::{Entities, Entity},
8-
system::{RunSystem, SystemId},
8+
system::{RunSystemWithInput, SystemId},
99
world::{EntityWorldMut, FromWorld, World},
1010
};
1111
use bevy_ecs_macros::SystemParam;
@@ -523,8 +523,26 @@ impl<'w, 's> Commands<'w, 's> {
523523
/// Running slow systems can become a bottleneck.
524524
///
525525
/// Calls [`World::run_system`](crate::system::World::run_system).
526+
///
527+
/// There is no way to get the output of a system when run as a command, because the
528+
/// execution of the system happens later. To get the output of a system, use
529+
/// [`World::run_system`] or [`World::run_system_with_input`] instead of running the system as a command.
526530
pub fn run_system(&mut self, id: SystemId) {
527-
self.queue.push(RunSystem::new(id));
531+
self.run_system_with_input(id, ());
532+
}
533+
534+
/// Runs the system corresponding to the given [`SystemId`].
535+
/// Systems are ran in an exclusive and single threaded way.
536+
/// Running slow systems can become a bottleneck.
537+
///
538+
/// Calls [`World::run_system_with_input`](crate::system::World::run_system_with_input).
539+
///
540+
/// There is no way to get the output of a system when run as a command, because the
541+
/// execution of the system happens later. To get the output of a system, use
542+
/// [`World::run_system`] or [`World::run_system_with_input`] instead of running the system as a command.
543+
pub fn run_system_with_input<I: 'static + Send>(&mut self, id: SystemId<I>, input: I) {
544+
self.queue
545+
.push(RunSystemWithInput::new_with_input(id, input));
528546
}
529547

530548
/// Pushes a generic [`Command`] to the command queue.

0 commit comments

Comments
 (0)