Skip to content

Reflect: Allow to override the type name #3327

Closed
@jcornaz

Description

@jcornaz

What problem does this solve or what need does it fill?

As a plugin author I publish components and implement Reflect for them so that the consumers of my plugin can use them in serialized scenes.

Theses components may live in private modules and be re-exported from a parent module like this:

mod my_private_module {
  #[derive(Debug, Copy, Clone, Default, Component, Reflect]
  #[reflect(Component)]
  pub struct AwesomeComponent;
}

// Expose the component without the user knowing about `my_private_module`
pub use my_private_module::AwesomeComponent;

This as the advantage that moving the component to another module or rename/move the module is not a breaking change for the consumers of my library.

But when serialized via bevy's reflection system, it exposes the real path of the component. So moving my Component is now a breaking change. And that's annoying.

What solution would you like?

I would like to be able to choose (hard-code) the path of my components. Maybe like this:

#[derive(Debug, Copy, Clone, Default, Component, Reflect]
#[reflect(Component)]
#[reflect(rename = "myplugin::AwesomeComponent")] // <-- Choose a type name
pub struct AwesomeComponent;;

What alternative(s) have you considered?

I could not move my components (annoying for me). Or I could publish a breaking change (annoying for my users).

Additional context

Serde has a somewhat similar feature:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions