Skip to content

ExtractComponent creates required components on extract #19941

@tychedelia

Description

@tychedelia

Problem:

Components that have both #[derive(ExtractComponent)] and #[require] attributes create their required components when extracting into the render world, which is probably not what the user intended and can lead to surprising results.

@robtfm identified the following cases:

  • Camera2d - has ExtractComponent and requires Camera (+ other components)
  • Camera3d - has ExtractComponent and requires Camera (+ other components)
  • ClusteredDecal - has ExtractComponent and requires Transform, Visibility, VisibilityClass
  • ScreenSpaceAmbientOcclusion - has ExtractComponent and requires DepthPrepass, NormalPrepass
  • FogVolume - has ExtractComponent and requires Transform, Visibility
  • AmbientLight has #[require(Camera)] which doesn't make semantic sense (AmbientLight is not IsA Camera)
  • MaterialNode is being extracted but probably shouldn't be

Solution

  1. Add compile-time error when a component has both ExtractComponent and #[require] attributes
  2. Newtype the affected components for extraction to avoid the require behavior
  3. Remove #[require(Camera)] from AmbientLight
  4. Remove extraction from MaterialNode if not needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-BugAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions