Skip to content

Commit 476b5a6

Browse files
alice-i-cecileexjam
authored andcommitted
Remind users to initialize their systems before running them (bevyengine#3947)
# Objective - Manually running systems is a somewhat obscure process: systems must be initialized before they are run - The unwrap is rather hard to debug. ## Solution - Replace unwraps in `FunctionSystem` methods with expects (progress towards bevyengine#3892). - Briefly document this requirement.
1 parent 7477c97 commit 476b5a6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/bevy_ecs/src/system/function_system.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ pub struct InputMarker;
305305
/// You get this by calling [`IntoSystem::into_system`] on a function that only accepts
306306
/// [`SystemParam`]s. The output of the system becomes the functions return type, while the input
307307
/// becomes the functions [`In`] tagged parameter or `()` if no such parameter exists.
308+
///
309+
/// [`FunctionSystem`] must be `.initialized` before they can be run.
308310
pub struct FunctionSystem<In, Out, Param, Marker, F>
309311
where
310312
Param: SystemParam,
@@ -378,7 +380,7 @@ where
378380
let change_tick = world.increment_change_tick();
379381
let out = self.func.run(
380382
input,
381-
self.param_state.as_mut().unwrap(),
383+
self.param_state.as_mut().expect("System's param_state was not found. Did you forget to initialize this system before running it?"),
382384
&self.system_meta,
383385
world,
384386
change_tick,
@@ -389,7 +391,7 @@ where
389391

390392
#[inline]
391393
fn apply_buffers(&mut self, world: &mut World) {
392-
let param_state = self.param_state.as_mut().unwrap();
394+
let param_state = self.param_state.as_mut().expect("System's param_state was not found. Did you forget to initialize this system before running it?");
393395
param_state.apply(world);
394396
}
395397

0 commit comments

Comments
 (0)