@@ -56,6 +56,40 @@ impl SystemMeta {
56
56
// TODO: Actually use this in FunctionSystem. We should probably only do this once Systems are constructed using a World reference
57
57
// (to avoid the need for unwrapping to retrieve SystemMeta)
58
58
/// Holds on to persistent state required to drive [`SystemParam`] for a [`System`].
59
+ ///
60
+ /// This is a very powerful and convenient tool for working with exclusive world access,
61
+ /// allowing you to fetch data from the [`World`] as if you were running a [`System`].
62
+ ///
63
+ /// Borrow-checking is handled for you, allowing you to mutably acccess multiple compatible system parameters at once,
64
+ /// and arbitrary system parameters (like [`EventWriter`](crate::event::EventWriter)) can be conveniently fetched.
65
+ ///
66
+ /// # Example
67
+ /// ```rust
68
+ /// use bevy::ecs::system::SystemState;
69
+ /// use bevy::ecs::world::World;
70
+ ///
71
+ /// struct MyEvent;
72
+ /// struct MyResource(u32);
73
+ ///
74
+ /// #[derive(Component)]
75
+ /// struct MyComponent;
76
+ ///
77
+ /// // Work directly on the `World`
78
+ /// let mut world = World::new();
79
+ ///
80
+ /// // Construct a `SystemState` struct, passing in a tuple of `SystemParam`
81
+ /// // as if you were writing an ordinary system.
82
+ /// // This can be cached and reused for improved performance.
83
+ /// let mut system_state: SystemState<(
84
+ /// EventWriter<MyEvent>,
85
+ /// Option<ResMut<MyResource>>,
86
+ /// Query<&MyComponent>,
87
+ /// )> = SystemState::new(&mut world);
88
+ ///
89
+ /// // Use system_state.get_mut(&mut world) and unpack your system parameters into variables!
90
+ /// // You can use system_state.get(&world) instead for read-only versions of your system parameters
91
+ /// let (event_writer, maybe_respource, query) = system_state.get_mut(&mut world);
92
+ /// ```
59
93
pub struct SystemState < Param : SystemParam > {
60
94
meta : SystemMeta ,
61
95
param_state : <Param as SystemParam >:: Fetch ,
0 commit comments