Skip to content

Refactor extraction to bypass the orphan rules#22766

Open
kristoff3r wants to merge 7 commits intobevyengine:mainfrom
kristoff3r:ks/extract_refactor
Open

Refactor extraction to bypass the orphan rules#22766
kristoff3r wants to merge 7 commits intobevyengine:mainfrom
kristoff3r:ks/extract_refactor

Conversation

@kristoff3r
Copy link
Contributor

@kristoff3r kristoff3r commented Feb 1, 2026

Objective

Fixes #18722, and allows ExtractComponent to be used for foreign types.

Solution

  • Split the Out type from ExtractComponent to a SyncComponent trait. This allows types to use the synchronization logic without the extraction logic, and allows SyncComponentPlugin to correctly identify which components should be removed.
  • Don't delete the entire entity but only the Out components in SyncComponentPlugin/SyncWorldPlugin, fixing Use of SyncComponentPlugin on ExtractComponentPlugin causes RenderEntity to be incorrectly despawned #18722.
  • Add marker types to ExtractComponent and SyncComponent, allowing them to be implemented for foreign types outside bevy_render. (Example: DirectionalLight is defined in bevy_light which doesn't depend on bevy_render, and used by bevy_pbr. Without the marker no crate is allowed to implement the trait.)

During some earlier render crate refactors by @atlv24, some uses of ExtractComponent was converted to manual implementations. I have not ported these back, that can be done in follow up PRs.

As a follow up it might be interesting to make a derive macro for SyncComponent, and/or update the ExtractComponent macro to be able to customize the behavior around syncing.

Testing

Ran a bunch of the examples. It would be good to test others, especially ones that toggle components.

A test case is in #22758. If that one gets merged first this PR should be updated to uncomment the relevant assert.

@kristoff3r kristoff3r added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 1, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering (2026 Proposal) Feb 1, 2026
@atlv24 atlv24 self-requested a review February 1, 2026 16:27
Copy link
Contributor

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty clever, needs a migration guide though

@kristoff3r kristoff3r requested a review from tychedelia February 1, 2026 16:46
Copy link
Contributor

@atlv24 atlv24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad theres a way to clean this up and fix a bug too, excited to see this tucked away into a derive macro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status
Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Use of SyncComponentPlugin on ExtractComponentPlugin causes RenderEntity to be incorrectly despawned

2 participants