|
1 | 1 | //! This example demonstrates how fallible parameters can prevent their systems
|
2 | 2 | //! from running if their acquiry conditions aren't met.
|
3 | 3 | //!
|
4 |
| -//! Fallible parameters include: |
5 |
| -//! - [`Res<R>`], [`ResMut<R>`] - Resource has to exist. |
6 |
| -//! - [`Single<D, F>`] - There must be exactly one matching entity. |
7 |
| -//! - [`Option<Single<D, F>>`] - There must be zero or one matching entity. |
8 |
| -//! - [`Populated<D, F>`] - There must be at least one matching entity. |
| 4 | +//! Fallible system parameters include: |
| 5 | +//! - [`Res<R>`], [`ResMut<R>`] - Resource has to exist, and the [`GLOBAL_ERROR_HANDLER`] will be called if it doesn't. |
| 6 | +//! - [`Single<D, F>`] - There must be exactly one matching entity, but the system will be silently skipped otherwise. |
| 7 | +//! - [`Option<Single<D, F>>`] - There must be zero or one matching entity. The system will be silently skipped if there are more. |
| 8 | +//! - [`Populated<D, F>`] - There must be at least one matching entity, but the system will be silently skipped otherwise. |
9 | 9 | //!
|
10 |
| -//! To learn more about setting the fallback behavior for when a parameter fails to be fetched, |
| 10 | +//! Other system parameters, such as [`Query`], will never fail validation: returning a query with no matching entities is valid. |
| 11 | +//! |
| 12 | +//! The result of failed system parameter validation is determined by the [`ValidationOutcome`] returned |
| 13 | +//! by [`SystemParam::validate_param`] for each system parameter. |
| 14 | +//! Each system will pass, fail, or skip based on the joint outcome of all its parameters, |
| 15 | +//! according to the rules defined in [`ValidationOutcome::combine`]. |
| 16 | +//! |
| 17 | +//! To learn more about setting the fallback behavior for [`ValidationOutcome`] failures, |
11 | 18 | //! please see the `error_handling.rs` example.
|
| 19 | +//! |
| 20 | +//! [`ValidationOutcome`]: bevy::ecs::system::ValidationOutcome |
| 21 | +//! [`ValidationOutcome::combine`]: bevy::ecs::system::ValidationOutcome::combine |
| 22 | +//! [`SystemParam::validate_param`]: bevy::ecs::system::SystemParam::validate_param |
12 | 23 |
|
13 | 24 | use bevy::ecs::error::{warn, GLOBAL_ERROR_HANDLER};
|
14 | 25 | use bevy::prelude::*;
|
@@ -111,7 +122,7 @@ fn user_input(
|
111 | 122 | }
|
112 | 123 |
|
113 | 124 | // System that moves the enemies in a circle.
|
114 |
| -// Only runs if there are enemies. |
| 125 | +// Only runs if there are enemies, due to the `Populated` parameter. |
115 | 126 | fn move_targets(mut enemies: Populated<(&mut Transform, &mut Enemy)>, time: Res<Time>) {
|
116 | 127 | for (mut transform, mut target) in &mut *enemies {
|
117 | 128 | target.rotation += target.rotation_speed * time.delta_secs();
|
|
0 commit comments