File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
release-content/release-notes Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ title : Observer Run Conditions
3+ authors : ["@jonas-meyer"]
4+ pull_requests : [22602]
5+ ---
6+
7+ Observers can now use run conditions with ` .run_if() ` , the same pattern systems use for conditional execution.
8+
9+ ``` rust
10+ #[derive(Resource )]
11+ struct GamePaused (bool );
12+
13+ // Observer only runs when game is not paused
14+ app . add_observer (
15+ on_damage . run_if (| paused : Res <GamePaused >| ! paused . 0 )
16+ );
17+
18+ // Multiple conditions can be chained (AND semantics)
19+ app . add_observer (
20+ on_damage
21+ . run_if (| paused : Res <GamePaused >| ! paused . 0 )
22+ . run_if (resource_exists :: <Player >)
23+ );
24+ ```
25+
26+ This works with ` add_observer ` , entity ` .observe() ` , and the ` Observer ` builder pattern.
You can’t perform that action at this time.
0 commit comments