Skip to content

Commit 57086d4

Browse files
Remove the need to derive Event when deriving EntityEvent (#20104)
# Objective Since we are planning to remove the need to derive both `Event` and `EntityEvent` in 0.17 either way, I'm choosing to do the easy thing in this PR so we can get the churn out of the way early. Context from [discord](https://discordapp.com/channels/691052431525675048/1383928409784193024/1393463673137401946). Related to, and will conflict slightly with #20101. ## Solution - Derive `Event` as part of the `EntityEvent` derive - Remove any `Event` derives that were made unnecessary - Update release notes
1 parent 2bddbdf commit 57086d4

File tree

28 files changed

+53
-55
lines changed

28 files changed

+53
-55
lines changed

benches/benches/bevy_ecs/observers/propagation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn event_propagation(criterion: &mut Criterion) {
6161
group.finish();
6262
}
6363

64-
#[derive(Event, EntityEvent, Clone, Component)]
64+
#[derive(EntityEvent, Clone, Component)]
6565
#[entity_event(traversal = &'static ChildOf, auto_propagate)]
6666
struct TestEvent<const N: usize> {}
6767

benches/benches/bevy_ecs/observers/simple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::hint::black_box;
22

33
use bevy_ecs::{
4-
event::{EntityEvent, Event},
4+
event::EntityEvent,
55
observer::{On, TriggerTargets},
66
world::World,
77
};
@@ -13,7 +13,7 @@ fn deterministic_rand() -> ChaCha8Rng {
1313
ChaCha8Rng::seed_from_u64(42)
1414
}
1515

16-
#[derive(Clone, Event, EntityEvent)]
16+
#[derive(Clone, EntityEvent)]
1717
struct EventBase;
1818

1919
pub fn observe_simple(criterion: &mut Criterion) {

crates/bevy_animation/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ mod tests {
15341534

15351535
use super::*;
15361536

1537-
#[derive(Event, EntityEvent, Reflect, Clone)]
1537+
#[derive(EntityEvent, Reflect, Clone)]
15381538
struct A;
15391539

15401540
#[track_caller]

crates/bevy_app/src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ impl App {
13251325
/// # friends_allowed: bool,
13261326
/// # };
13271327
/// #
1328-
/// # #[derive(Event, EntityEvent)]
1328+
/// # #[derive(EntityEvent)]
13291329
/// # struct Invite;
13301330
/// #
13311331
/// # #[derive(Component)]

crates/bevy_core_widgets/src/core_checkbox.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use accesskit::Role;
22
use bevy_a11y::AccessibilityNode;
33
use bevy_app::{App, Plugin};
4-
use bevy_ecs::event::{EntityEvent, Event};
4+
use bevy_ecs::event::EntityEvent;
55
use bevy_ecs::query::{Has, Without};
66
use bevy_ecs::system::{In, ResMut};
77
use bevy_ecs::{
@@ -97,7 +97,7 @@ fn checkbox_on_pointer_click(
9797
/// commands.trigger_targets(SetChecked(true), checkbox);
9898
/// }
9999
/// ```
100-
#[derive(Event, EntityEvent)]
100+
#[derive(EntityEvent)]
101101
pub struct SetChecked(pub bool);
102102

103103
/// Event which can be triggered on a checkbox to toggle the checked state. This can be used to
@@ -119,7 +119,7 @@ pub struct SetChecked(pub bool);
119119
/// commands.trigger_targets(ToggleChecked, checkbox);
120120
/// }
121121
/// ```
122-
#[derive(Event, EntityEvent)]
122+
#[derive(EntityEvent)]
123123
pub struct ToggleChecked;
124124

125125
fn checkbox_on_set_checked(

crates/bevy_core_widgets/src/core_slider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ops::RangeInclusive;
33
use accesskit::{Orientation, Role};
44
use bevy_a11y::AccessibilityNode;
55
use bevy_app::{App, Plugin};
6-
use bevy_ecs::event::{EntityEvent, Event};
6+
use bevy_ecs::event::EntityEvent;
77
use bevy_ecs::hierarchy::Children;
88
use bevy_ecs::lifecycle::Insert;
99
use bevy_ecs::query::Has;
@@ -498,7 +498,7 @@ pub(crate) fn slider_on_insert_step(trigger: On<Insert, SliderStep>, mut world:
498498
/// commands.trigger_targets(SetSliderValue::Relative(-0.25), slider);
499499
/// }
500500
/// ```
501-
#[derive(Event, EntityEvent, Clone)]
501+
#[derive(EntityEvent, Clone)]
502502
pub enum SetSliderValue {
503503
/// Set the slider value to a specific value.
504504
Absolute(f32),

crates/bevy_ecs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ If the event is an `EntityEvent`, it can also be triggered to target specific en
333333
```rust
334334
use bevy_ecs::prelude::*;
335335

336-
#[derive(Event, EntityEvent)]
336+
#[derive(EntityEvent)]
337337
struct Explode;
338338

339339
let mut world = World::new();

crates/bevy_ecs/macros/src/component.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub fn derive_entity_event(input: TokenStream) -> TokenStream {
7373
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
7474

7575
TokenStream::from(quote! {
76+
impl #impl_generics #bevy_ecs_path::event::Event for #struct_name #type_generics #where_clause {}
7677
impl #impl_generics #bevy_ecs_path::event::EntityEvent for #struct_name #type_generics #where_clause {
7778
type Traversal = #traversal;
7879
const AUTO_PROPAGATE: bool = #auto_propagate;

crates/bevy_ecs/macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ pub fn derive_event(input: TokenStream) -> TokenStream {
557557
/// see full explanation on `EntityEvent` trait docs.
558558
///
559559
/// ```ignore
560-
/// #[derive(Event, EntityEvent)]
560+
/// #[derive(EntityEvent)]
561561
/// /// Traversal component
562562
/// #[entity_event(traversal = &'static ChildOf)]
563563
/// /// Always propagate

crates/bevy_ecs/src/event/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub trait Event: Send + Sync + 'static {
150150
/// # use bevy_ecs::prelude::*;
151151
/// #
152152
/// // When the `Damage` event is triggered on an entity, bubble the event up to ancestors.
153-
/// #[derive(Event, EntityEvent)]
153+
/// #[derive(EntityEvent)]
154154
/// #[entity_event(traversal = &'static ChildOf, auto_propagate)]
155155
/// struct Damage {
156156
/// amount: f32,
@@ -162,7 +162,7 @@ pub trait Event: Send + Sync + 'static {
162162
/// ```
163163
/// # use bevy_ecs::prelude::*;
164164
/// #
165-
/// # #[derive(Event, EntityEvent)]
165+
/// # #[derive(EntityEvent)]
166166
/// # #[entity_event(traversal = &'static ChildOf, auto_propagate)]
167167
/// # struct Damage {
168168
/// # amount: f32,
@@ -201,7 +201,7 @@ pub trait Event: Send + Sync + 'static {
201201
/// ```
202202
/// # use bevy_ecs::prelude::*;
203203
/// #
204-
/// # #[derive(Event, EntityEvent)]
204+
/// # #[derive(EntityEvent)]
205205
/// # #[entity_event(traversal = &'static ChildOf, auto_propagate)]
206206
/// # struct Damage {
207207
/// # amount: f32,
@@ -242,7 +242,7 @@ pub trait Event: Send + Sync + 'static {
242242
#[diagnostic::on_unimplemented(
243243
message = "`{Self}` is not an `EntityEvent`",
244244
label = "invalid `EntityEvent`",
245-
note = "consider annotating `{Self}` with `#[derive(Event, EntityEvent)]`"
245+
note = "consider annotating `{Self}` with `#[derive(EntityEvent)]`"
246246
)]
247247
pub trait EntityEvent: Event {
248248
/// The component that describes which [`Entity`] to propagate this event to next, when [propagation] is enabled.

0 commit comments

Comments
 (0)