You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm adopting this ~~child~~ PR.
# Objective
- Working with exclusive world access is not always easy: in many cases,
a standard system or three is more ergonomic to write, and more
modularly maintainable.
- For small, one-off tasks (commonly handled with scripting), running an
event-reader system incurs a small but flat overhead cost and muddies
the schedule.
- Certain forms of logic (e.g. turn-based games) want very fine-grained
linear and/or branching control over logic.
- SystemState is not automatically cached, and so performance can suffer
and change detection breaks.
- Fixes#2192.
- Partial workaround for #279.
## Solution
- Adds a SystemRegistry resource to the World, which stores initialized
systems keyed by their SystemSet.
- Allows users to call world.run_system(my_system) and
commands.run_system(my_system), without re-initializing or losing state
(essential for change detection).
- Add a Callback type to enable convenient use of dynamic one shot
systems and reduce the mental overhead of working with Box<dyn
SystemSet>.
- Allow users to run systems based on their SystemSet, enabling more
complex user-made abstractions.
## Future work
- Parameterized one-shot systems would improve reusability and bring
them closer to events and commands. The API could be something like
run_system_with_input(my_system, my_input) and use the In SystemParam.
- We should evaluate the unification of commands and one-shot systems
since they are two different ways to run logic on demand over a World.
### Prior attempts
- #2234
- #2417
- #4090
- #7999
This PR continues the work done in
#7999.
---------
Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: Federico Rinaldi <[email protected]>
Co-authored-by: MinerSebas <[email protected]>
Co-authored-by: Aevyrie <[email protected]>
Co-authored-by: Alejandro Pascual Pozo <[email protected]>
Co-authored-by: Rob Parrett <[email protected]>
Co-authored-by: François <[email protected]>
Co-authored-by: Dmytro Banin <[email protected]>
Co-authored-by: James Liu <[email protected]>
Copy file name to clipboardExpand all lines: crates/bevy_ecs/src/system/function_system.rs
+5-1Lines changed: 5 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -72,8 +72,10 @@ impl SystemMeta {
72
72
// (to avoid the need for unwrapping to retrieve SystemMeta)
73
73
/// Holds on to persistent state required to drive [`SystemParam`] for a [`System`].
74
74
///
75
-
/// This is a very powerful and convenient tool for working with exclusive world access,
75
+
/// This is a powerful and convenient tool for working with exclusive world access,
76
76
/// allowing you to fetch data from the [`World`] as if you were running a [`System`].
77
+
/// However, simply calling `world::run_system(my_system)` using a [`World::run_system`](crate::system::World::run_system)
78
+
/// can be significantly simpler and ensures that change detection and command flushing work as expected.
77
79
///
78
80
/// Borrow-checking is handled for you, allowing you to mutably access multiple compatible system parameters at once,
79
81
/// and arbitrary system parameters (like [`EventWriter`](crate::event::EventWriter)) can be conveniently fetched.
@@ -89,6 +91,8 @@ impl SystemMeta {
89
91
/// - [`Local`](crate::system::Local) variables that hold state
90
92
/// - [`EventReader`](crate::event::EventReader) system parameters, which rely on a [`Local`](crate::system::Local) to track which events have been seen
91
93
///
94
+
/// Note that this is automatically handled for you when using a [`World::run_system`](crate::system::World::run_system).
0 commit comments