Skip to content

Conditional observers in bsn! - #25650

Open
hxYuki wants to merge 2 commits into
bevyengine:mainfrom
hxYuki:bsn-on-condition
Open

Conditional observers in bsn!#25650
hxYuki wants to merge 2 commits into
bevyengine:mainfrom
hxYuki:bsn-on-condition

Conversation

@hxYuki

@hxYuki hxYuki commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Objective

  • Conditional observers in bsn!
  • We have run_if() for observer systems, but IntoObserverSystem doesn't accept ObserverWithCondition which prevents adding conditions over observer in bsn!. And ObserverWithCondition is not cloneable, thus cannot be used in scene.

Solution

  • Add a ConditionalOnTemplate, which holds the condition(s) and call Observer::run_if on build_template.
  • Connect new condition with and_eager() when ConditionalOnTemplate::run_if called.
  • Create ConditionalOnTemplate from OnTemplate via OnTemplate::run_if.

Testing

  • Tested with on(|_event: On<PointerPress>| println!("Ok pressed!")).run_if(|| false) locally.

Showcase

bsn! {
    @button("Ok")
    on(|_event: On<PointerPress>| println!("Ok pressed!")).run_if(|| false)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant