bevy/crates
Alice Cecile b7d2cb8547
Provide access to the original target of entity-events in observers (#19663)
# Objective

Getting access to the original target of an entity-event is really
helpful when working with bubbled / propagated events.

`bevy_picking` special-cases this, but users have requested this for all
sorts of bubbled events.

The existing naming convention was also very confusing. Fixes
https://github.com/bevyengine/bevy/issues/17112, but also see #18982.

## Solution

1. Rename `ObserverTrigger::target` -> `current_target`.
1. Store `original_target: Option<Entity>` in `ObserverTrigger`.
1. Wire it up so this field gets set correctly.
1. Remove the `target` field on the `Pointer` events from
`bevy_picking`.

Closes https://github.com/bevyengine/bevy/pull/18710, which attempted
the same thing. Thanks @emfax!

## Testing

I've modified an existing test to check that the entities returned
during event bubbling / propagation are correct.

## Notes to reviewers

It's a little weird / sad that you can no longer access this infromation
via the buffered events for `Pointer`. That said, you already couldn't
access any bubbled target. We should probably remove the `BufferedEvent`
form of `Pointer` to reduce confusion and overhead, but I didn't want to
do so here.

Observer events can be trivially converted into buffered events (write
an observer with an EventWriter), and I suspect that that is the better
migration if you want the controllable timing or performance
characteristics of buffered events for your specific use case.

## Future work

It would be nice to not store this data at all (and not expose any
methods) if propagation was disabled. That involves more trait
shuffling, and I don't think we should do it here for reviewability.

---------

Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
2025-06-15 20:53:25 +00:00
..
bevy_a11y Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_animation Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_anti_aliasing bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_app Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_asset Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_audio Fix iOS simulator build (#19498) 2025-06-10 17:01:37 +00:00
bevy_color Make sequential_dispersed fn constant (#19659) 2025-06-15 16:56:07 +00:00
bevy_core_pipeline Component lifecycle reorganization and documentation (#19543) 2025-06-10 00:59:16 +00:00
bevy_core_widgets Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_derive bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_dev_tools Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_diagnostic bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_dylib bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_ecs Provide access to the original target of entity-events in observers (#19663) 2025-06-15 20:53:25 +00:00
bevy_encase_derive bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_gilrs Make GILRS and WINIT_WINDOWS public (#19575) 2025-06-12 20:05:00 +00:00
bevy_gizmos Stop storing access for all systems (#19477) 2025-06-13 17:56:09 +00:00
bevy_gltf bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_image Add missing docs for ImageLoader (#19499) 2025-06-09 19:46:33 +00:00
bevy_input Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_input_focus Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_internal Initial raytraced lighting progress (bevy_solari) (#19058) 2025-06-12 21:26:10 +00:00
bevy_log Fix iOS simulator build (#19498) 2025-06-10 17:01:37 +00:00
bevy_macro_utils bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_math Improve Bevy's double-precision story for third-party crates (#19194) 2025-06-08 02:02:47 +00:00
bevy_mesh Initial raytraced lighting progress (bevy_solari) (#19058) 2025-06-12 21:26:10 +00:00
bevy_mikktspace deny(missing_docs) for bevy_mikktspace (#19654) 2025-06-15 16:50:23 +00:00
bevy_pbr Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_picking Provide access to the original target of entity-events in observers (#19663) 2025-06-15 20:53:25 +00:00
bevy_platform bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_ptr bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_reflect Bump ron version to 0.10. (#19631) 2025-06-13 19:54:31 +00:00
bevy_remote Component lifecycle reorganization and documentation (#19543) 2025-06-10 00:59:16 +00:00
bevy_render Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_scene Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_solari Initial raytraced lighting progress (bevy_solari) (#19058) 2025-06-12 21:26:10 +00:00
bevy_sprite bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_state Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_tasks Added async_executor to the array of features enabled by multi_threaded within bevy_tasks crate to prevent compile-time error when default-features are disabled. (#19334) 2025-06-10 00:54:46 +00:00
bevy_text Adding PartialEq to some UI and Text types (#19552) 2025-06-09 20:08:17 +00:00
bevy_time Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_transform bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_ui Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_utils bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_window Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00
bevy_winit Event Split: Event, EntityEvent, and BufferedEvent (#19647) 2025-06-15 16:46:34 +00:00