diff --git a/_release-content/migration-guides/observe_bundle_helper_deprecation.md b/_release-content/migration-guides/observe_bundle_helper_deprecation.md new file mode 100644 index 0000000000000..2de24e47959ac --- /dev/null +++ b/_release-content/migration-guides/observe_bundle_helper_deprecation.md @@ -0,0 +1,34 @@ +--- +title: "`bevy_ui_widgets::observe` has been deprecated in favor of `bsn!`" +pull_requests: [23730] +--- + +The `observe` function and `AddObserver` struct in `bevy_ui_widgets` have been deprecated. +These were a workaround for attaching observers as bundle effects. +Now that `bsn!` supports the `on` helper natively, use that instead. + +Before: + +```rust +use bevy_ui_widgets::observe; + +commands.spawn(( + Button, + observe(|_event: On>| { + println!("Clicked!"); + }), +)); +``` + +After: + +```rust +commands.spawn(bsn! { + Button + on(|_event: On>| { + println!("Clicked!"); + }) +}); +``` + +If you were using `AddObserver` directly for some reason, replace it with `on` inside a `bsn!` block in the same way. diff --git a/crates/bevy_feathers/src/controls/virtual_keyboard.rs b/crates/bevy_feathers/src/controls/virtual_keyboard.rs index 3d87a3c99fd00..9ddc93b03cca1 100644 --- a/crates/bevy_feathers/src/controls/virtual_keyboard.rs +++ b/crates/bevy_feathers/src/controls/virtual_keyboard.rs @@ -81,7 +81,7 @@ where /// /// These events can be disabled by adding an [`bevy_ui::InteractionDisabled`] component to the entity #[deprecated(since = "0.19.0", note = "Use the virtual_keyboard() BSN function")] -#[expect(deprecated, reason = "uses the deprecated button_bundle")] +#[expect(deprecated, reason = "uses the deprecated button_bundle and observe")] pub fn virtual_keyboard_bundle( keys: impl Iterator> + Send + Sync + 'static, ) -> impl Bundle diff --git a/crates/bevy_ui_widgets/src/observe.rs b/crates/bevy_ui_widgets/src/observe.rs index 944d0c198dd21..cbeef48df39e8 100644 --- a/crates/bevy_ui_widgets/src/observe.rs +++ b/crates/bevy_ui_widgets/src/observe.rs @@ -1,6 +1,8 @@ -// TODO: This probably doesn't belong in bevy_ui_widgets, but I am not sure where it should go. -// It is certainly a useful thing to have. #![expect(unsafe_code, reason = "Unsafe code is used to improve performance.")] +#![expect( + deprecated, + reason = "We need to use the pre-existing tools until this is removed." +)] use core::{marker::PhantomData, mem}; @@ -11,6 +13,10 @@ use bevy_ecs::{ }; /// Helper struct that adds an observer when inserted as a [`Bundle`]. +#[deprecated( + since = "0.19.0", + note = "Use the `on` helper with bsn! instead to spawn observers as part of ECS hierarchies." +)] pub struct AddObserver> { observer: I, marker: PhantomData<(E, B, M)>, @@ -74,6 +80,10 @@ impl> DynamicBundle } /// Adds an observer as a bundle effect. +#[deprecated( + since = "0.19.0", + note = "Use the `on` helper with bsn! instead to spawn observers as part of ECS hierarchies." +)] pub fn observe>( observer: I, ) -> AddObserver {