From b3ed0dd002bd8e45f3e3802d5c020766f1a4013d Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Wed, 1 May 2024 14:47:11 -0400 Subject: [PATCH] Add Reflect derive to Events and contained types (#13149) # Objective The `Events` containerr should be reflectable, in order to make dev tools that examine its state more useful. Fixes #13148. ## Solution - Add a `Reflect` derive to `Events`, gated behind the `bevy_reflect` feature - Add `Reflect` to the contained types to make everything compile. --------- Co-authored-by: Alice Cecile --- crates/bevy_ecs/src/event.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index f5c84baf6f146..d4fada1139298 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -11,6 +11,8 @@ use crate::{ }; pub use bevy_ecs_macros::Event; use bevy_ecs_macros::SystemSet; +#[cfg(feature = "bevy_reflect")] +use bevy_reflect::Reflect; use bevy_utils::detailed_trace; use std::ops::{Deref, DerefMut}; use std::{ @@ -34,10 +36,12 @@ pub trait Event: Send + Sync + 'static {} /// sent to the point it was processed. `EventId`s increase montonically by send order. /// /// [`World`]: crate::world::World +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] pub struct EventId { /// Uniquely identifies the event associated with this ID. // This value corresponds to the order in which each event was added to the world. pub id: usize, + #[cfg_attr(feature = "bevy_reflect", reflect(ignore))] _marker: PhantomData, } @@ -93,6 +97,7 @@ impl Hash for EventId { } #[derive(Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] struct EventInstance { pub event_id: EventId, pub event: E, @@ -171,6 +176,7 @@ struct EventInstance { /// [Example usage standalone.](https://github.com/bevyengine/bevy/blob/latest/crates/bevy_ecs/examples/events.rs) /// #[derive(Debug, Resource)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] pub struct Events { /// Holds the oldest still active events. /// Note that `a.start_event_count + a.len()` should always be equal to `events_b.start_event_count`. @@ -393,6 +399,7 @@ impl Extend for Events { } #[derive(Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] struct EventSequence { events: Vec>, start_event_count: usize,