Refactor extraction to bypass the orphan rules#22766
Open
kristoff3r wants to merge 7 commits intobevyengine:mainfrom
Open
Refactor extraction to bypass the orphan rules#22766kristoff3r wants to merge 7 commits intobevyengine:mainfrom
kristoff3r wants to merge 7 commits intobevyengine:mainfrom
Conversation
atlv24
reviewed
Feb 1, 2026
Contributor
atlv24
left a comment
There was a problem hiding this comment.
this is pretty clever, needs a migration guide though
atlv24
approved these changes
Feb 1, 2026
Contributor
atlv24
left a comment
There was a problem hiding this comment.
glad theres a way to clean this up and fix a bug too, excited to see this tucked away into a derive macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Fixes #18722, and allows
ExtractComponentto be used for foreign types.Solution
Outtype fromExtractComponentto aSyncComponenttrait. This allows types to use the synchronization logic without the extraction logic, and allowsSyncComponentPluginto correctly identify which components should be removed.Outcomponents inSyncComponentPlugin/SyncWorldPlugin, fixing Use ofSyncComponentPluginonExtractComponentPlugincausesRenderEntityto be incorrectly despawned #18722.ExtractComponentandSyncComponent, allowing them to be implemented for foreign types outsidebevy_render. (Example:DirectionalLightis defined inbevy_lightwhich doesn't depend onbevy_render, and used bybevy_pbr. Without the marker no crate is allowed to implement the trait.)During some earlier render crate refactors by @atlv24, some uses of
ExtractComponentwas 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 theExtractComponentmacro 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.