Skip to content

Reflection: Add distinction between ignoring fields for purposes of scene deserialization and external visibility #5245

@makspll

Description

@makspll

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

This stems from a discussion on discord.

Currently the reflection system is closely coupled with scene serialisation. This unavoidably causes the propagation of #[reflect(ignore)]'s throughout the codebase on fields which:

  1. are part of the public interface
  2. do implement Reflect
  3. are not intended to be serialized to the scene
    An example of this can be seen in bevy::render::Camera :
#[derive(Component, Debug, Reflect, Clone)]
#[reflect(Component)]
pub struct Camera {
    /// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`].
    pub viewport: Option<Viewport>,
    /// Cameras with a lower priority will be rendered before cameras with a higher priority.
    pub priority: isize,
    /// If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this
    /// camera will not be rendered.
    pub is_active: bool,
    /// The method used to calculate this camera's depth. This will be used for projections and visibility.
    pub depth_calculation: DepthCalculation,
    /// Computed values for this camera, such as the projection matrix and the render target size.
    #[reflect(ignore)]
    pub computed: ComputedCameraValues,
    /// The "target" that this camera will render to.
    #[reflect(ignore)]
    pub target: RenderTarget,
}

in this example RenderTarget should not be hidden away from for example script users or the editor. There is tension between goals 1. and 3.

What solution would you like?

Separate the notions of ignoring fields from reflection and just serialization,
perhaps an attribute like: #[reflect(dont_scene_serialize)]
would help make the intent clearer and solve the tension between two different use cases.

What alternative(s) have you considered?

  • Making serialisation to scene opt-in, by perhaps introducing another trait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions