Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "`bevy_ui_widgets::observe` has been deprecated in favor of `bsn!`"
pull_requests: [TODO]
---

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<Pointer<Press>>| {
println!("Clicked!");
}),
));
```

After:

```rust
commands.spawn(bsn! {
Button
on(|_event: On<Pointer<Press>>| {
println!("Clicked!");
})
});
```

If you were using `AddObserver` directly for some reason, replace it with `on` inside a `bsn!` block in the same way.
2 changes: 1 addition & 1 deletion crates/bevy_feathers/src/controls/virtual_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
keys: impl Iterator<Item = Vec<T>> + Send + Sync + 'static,
) -> impl Bundle
Expand Down
14 changes: 12 additions & 2 deletions crates/bevy_ui_widgets/src/observe.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>> {
observer: I,
marker: PhantomData<(E, B, M)>,
Expand Down Expand Up @@ -74,6 +80,10 @@ impl<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>> 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<E: EntityEvent, B: Bundle, M, I: IntoObserverSystem<E, B, M>>(
observer: I,
) -> AddObserver<E, B, M, I> {
Expand Down
Loading