Skip to content

Commit b8416b3

Browse files
authored
Add some missing reflect attributes (#14259)
# Objective - Some types are missing reflection attributes, which means we can't use them in scene serialization etc. - Effected types - `BorderRadius` - `AnimationTransitions` - `OnAdd` - `OnInsert` - `OnRemove` - My use-case for `OnAdd` etc to derive reflect is 'Serializable Observer Components'. Add the component, save the scene, then the observer is re-added on scene load. ```rust #[derive(Reflect)] struct MySerializeableObserver<T: Event>(#[reflect(ignore)]PhantomData<T>); impl<T: Event> Component for MySerializeableObserver<T> { const STORAGE_TYPE: StorageType = StorageType::Table; fn register_component_hooks(hooks: &mut ComponentHooks) { hooks.on_add(|mut world, entity, _| { world .commands() .entity(entity) .observe(|_trigger: Trigger<T>| { println!("it triggered etc."); }); }); } } ``` ## Solution - Add the missing traits ---
1 parent 453e0e4 commit b8416b3

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

crates/bevy_animation/src/transition.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
66
use bevy_ecs::{
77
component::Component,
8+
reflect::ReflectComponent,
89
system::{Query, Res},
910
};
10-
use bevy_reflect::Reflect;
11+
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1112
use bevy_time::Time;
1213
use bevy_utils::Duration;
1314

@@ -28,6 +29,7 @@ use crate::{graph::AnimationNodeIndex, ActiveAnimation, AnimationPlayer};
2829
/// component to get confused about which animation is the "main" animation, and
2930
/// transitions will usually be incorrect as a result.
3031
#[derive(Component, Default, Reflect)]
32+
#[reflect(Component, Default)]
3133
pub struct AnimationTransitions {
3234
main_animation: Option<AnimationNodeIndex>,
3335
transitions: Vec<AnimationTransition>,

crates/bevy_ecs/src/world/component_constants.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::*;
22
use crate::{self as bevy_ecs};
3+
#[cfg(feature = "bevy_reflect")]
4+
use bevy_reflect::Reflect;
35
/// Internal components used by bevy with a fixed component id.
46
/// Constants are used to skip [`TypeId`] lookups in hot paths.
57
@@ -14,10 +16,12 @@ pub const ON_REMOVE: ComponentId = ComponentId::new(3);
1416

1517
/// Trigger emitted when a component is added to an entity.
1618
#[derive(Event)]
19+
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
1720
pub struct OnAdd;
1821

1922
/// Trigger emitted when a component is inserted onto an entity.
2023
#[derive(Event)]
24+
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
2125
pub struct OnInsert;
2226

2327
/// Trigger emitted when a component is replaced on an entity.
@@ -26,4 +30,5 @@ pub struct OnReplace;
2630

2731
/// Trigger emitted when a component is removed from an entity.
2832
#[derive(Event)]
33+
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
2934
pub struct OnRemove;

crates/bevy_ui/src/ui_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,7 @@ impl Default for ZIndex {
19881988
///
19891989
/// <https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius>
19901990
#[derive(Component, Copy, Clone, Debug, PartialEq, Reflect)]
1991-
#[reflect(PartialEq, Default)]
1991+
#[reflect(Component, PartialEq, Default)]
19921992
#[cfg_attr(
19931993
feature = "serialize",
19941994
derive(serde::Serialize, serde::Deserialize),

0 commit comments

Comments
 (0)