Skip to content

Add some missing reflect attributes#14259

Merged
alice-i-cecile merged 5 commits intobevyengine:mainfrom
mrchantey:add-reflect-attributes
Jul 22, 2024
Merged

Add some missing reflect attributes#14259
alice-i-cecile merged 5 commits intobevyengine:mainfrom
mrchantey:add-reflect-attributes

Conversation

@mrchantey
Copy link
Contributor

@mrchantey mrchantey commented Jul 10, 2024

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.
#[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

@mrchantey mrchantey changed the title Add reflect attributes Add some missing reflect attributes Jul 10, 2024
@MrGVSV MrGVSV added D-Trivial Nice and easy! A great choice to get started with Bevy A-ECS Entities, components, systems, and events A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Animation Make things move and change over time A-Reflection Runtime information about types S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 10, 2024
@mweatherley mweatherley added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 11, 2024
@alice-i-cecile alice-i-cecile added this to the 0.14.1 milestone Jul 15, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 22, 2024
Merged via the queue into bevyengine:main with commit b8416b3 Jul 22, 2024
@mrchantey mrchantey deleted the add-reflect-attributes branch July 22, 2024 23:12
mockersf pushed a commit that referenced this pull request Aug 2, 2024
# 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

---
stepancheg pushed a commit to stepancheg/bevy that referenced this pull request Oct 20, 2024
…evyengine#16018)

# Objective

Built-in observers & events should be `Reflect` so that components that
interact with them can be serialized in scenes. This is a similar pr to
bevyengine#14259.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Animation Make things move and change over time A-ECS Entities, components, systems, and events A-Reflection Runtime information about types A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants