Skip to content

Make ExtractComponentPlugin etc. generic on AppLabel#24423

Open
Zeophlite wants to merge 14 commits into
bevyengine:mainfrom
Zeophlite:ee-sync4
Open

Make ExtractComponentPlugin etc. generic on AppLabel#24423
Zeophlite wants to merge 14 commits into
bevyengine:mainfrom
Zeophlite:ee-sync4

Conversation

@Zeophlite

@Zeophlite Zeophlite commented May 24, 2026

Copy link
Copy Markdown
Contributor

Objective

  • Bevy's extraction process is implicitly for copying data from the main sub-app to the RenderApp sub-app
  • Penultimate PR towards making the extract infra is reusable for non-rendering crates (see bevy_extract tracking #24483 )

e.g.

// Extract a component from the main subapp to the render subapp, and the audio subapp

#[derive(Component, Clone, Debug, ExtractComponent)]
#[extract_app(RenderApp, AudioApp)]
struct SomeComponent;

Solution

Followed by final PR in tracking issue is #22852 , which moves extraction to a new crate - as such, this PR retains "render" specific language where it was too awkward to change

Please review commit-by-commit

  • 751031749f - Add Default to AppLabel's
  • ff2fd56857 - Generalise SyncToRenderWorld = SyncToSubWorld<RenderApp> and RenderEntity = SubEntity<RenderApp>
  • 8d7d5a4f70 - Generalise entity_sync_system to use AppLabel (ExtractPlugin specifies entity_sync_system::<RenderApp>)
  • c7052bdd50 - Update ExtractInstance to be explicit for RenderApp . Update ExtractInstancesPlugin to be generic on AppLabel
  • 1816340fae
    • Update ExtractComponentPlugin to be generic on L : AppLabel = RenderApp - in followup PR we will remove this default.
    • Same for ExtractResourcePlugin and SyncComponentPlugin.
    • Update SyncWorldPlugin to be generic on AppLabel.
    • Update ExtractPlugin to be generic on AppLabel.
    • Update RenderPlugin to specify ExtractPlugin<RenderApp>.
  • fabe19de6e - Update SyncComponentPlugin to use an observer, rather than hook
  • 899ee25caa - Dual extraction
  • fdca1f24e9 - Support #[extract_app(AppA,AppB)] in derive(ExtractComponent)
  • 2a68d73ba1 - Merge migration guides
  • d318511cd0 - CI fixes

Simplified by #23377

Testing

  • CI
  • cargo run --example animated_mesh

@Zeophlite
Zeophlite force-pushed the ee-sync4 branch 2 times, most recently from 411e873 to 475796e Compare May 25, 2026 11:05
@github-actions

Copy link
Copy Markdown
Contributor

You added a new example but didn't add metadata for it. Please update the root Cargo.toml file.

@laundmo laundmo added A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change labels May 25, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering May 25, 2026
@laundmo laundmo added the X-Contentious There are nontrivial implications that should be thought through label May 25, 2026
@Zeophlite Zeophlite added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label May 25, 2026
@Zeophlite
Zeophlite force-pushed the ee-sync4 branch 10 times, most recently from cebeed8 to cffe2f2 Compare May 29, 2026 09:20
@Zeophlite Zeophlite changed the title WIP Extract Extract Extract Extract prework May 29, 2026
@Zeophlite Zeophlite added S-Blocked This cannot move forward until something else changes and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 29, 2026
@Zeophlite
Zeophlite marked this pull request as ready for review May 29, 2026 10:12
@Zeophlite Zeophlite added this to the 0.20 milestone May 29, 2026
@Zeophlite Zeophlite added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label May 29, 2026
@Zeophlite Zeophlite changed the title Extract Extract prework Extend ExtractComponentPlugin etc. to specify AppLabel Jun 3, 2026
@Zeophlite Zeophlite changed the title Extend ExtractComponentPlugin etc. to specify AppLabel Make ExtractComponentPlugin etc. generic on AppLabel Jun 14, 2026
Zeophlite added a commit to Zeophlite/bevy that referenced this pull request Jul 7, 2026
…ExtractComponent` / `ExtractResource` (bevyengine#24420)

# Objective

- Bevy's extraction process is implicitly for copying data from the main
sub-app to the `RenderApp` sub-app
- There is two user facing ways to set a component as extractable from
the main world to the render world, `#[derive(ExtractComponent)]` (this
is preferential) , or `impl ExtractComponent for Foo {}` (similarly for
`ExtractResource` and `SyncComponent` ) .
- To make extraction possible to different sub-apps, we need to mark all
these as explicitly for `RenderApp`
- Step towards making the extract infra is reusable for non-rendering
crates (see bevyengine#24483 )

## Solution

- Allow `ExtractComponent` , `ExtractResource` and `SyncComponent` to
specify the `AppLabel` the trait is implemented for. The corresponding
plugin is only implemented for `RenderApp` .
- For each explicit `impl`, specify `RenderApp` , e.g. `impl
ExtractComponent<RenderApp> for Foo {}`
- For each derive `ExtractComponent` and `ExtractResource` , specify the
`AppLabel` with the attribute `#[extract_app(RenderApp)]`
- This PR has no functionality change, that comes in the followup PRs
(see above issue, next PR is
bevyengine#24423 )

## Reviewer Notes

Wow 64 files changed! But it's really just 7 files, the rest is
mechanical

-
[_release-content/migration-guides/extract-extract-b.md](https://github.com/bevyengine/bevy/pull/24420/changes#diff-29ebde0ac49075715530302b4377b886582935440e61b0bd434fb17a8a5993f4)
- summarises the changes in the rest of the files
-
[crates/bevy_render/macros/src/extract_component.rs](https://github.com/bevyengine/bevy/pull/24420/changes#diff-5bc5fa18031ec9205350ff74096045895df0dd4767143ba9af86278015124e33)
- changes to `derive(ExtractComponent)`
-
[crates/bevy_render/macros/src/extract_resource.rs](https://github.com/bevyengine/bevy/pull/24420/changes#diff-2677783e1ce394eef4f3c01ceab81dccbe63ecf2637dc7c889afb44fe51f931c)
- changes to `derive(ExtractResource)`
-
[crates/bevy_render/macros/src/lib.rs](https://github.com/bevyengine/bevy/pull/24420/changes#diff-32a45af239b400c46709759c47ba8cacd1e9d0c8baa374aab24e4b05a976413e)
- changes to macro call sites
-
[crates/bevy_render/src/extract_component.rs](https://github.com/bevyengine/bevy/pull/24420/changes#diff-5ba2e960dccc637f00ad81decfa72dff06e9d54fbd9dcffd0750b2fb9349555f)
- changes to `ExtractComponent` trait
-
[crates/bevy_render/src/extract_resource.rs](https://github.com/bevyengine/bevy/pull/24420/changes#diff-12bf0dc2dfa36f71e5222de770bbf3c8ab9f04fe6581d2c76e12842abcc0a1c5)
- changes to `ExtractResource` trait
-
[crates/bevy_render/src/sync_component.rs](https://github.com/bevyengine/bevy/pull/24420/changes#diff-e86373d51ea0dc296bf1b3db6584aaa1c53baadbae3a34f47082bc4ad9f89777)
- changes to `SyncComponent` trait

I suggest first reading the `ExtractResource` changes as a starting
point

## Testing

- CI
- `cargo run --example animated_mesh`
- Follow up PRs (see tracking issue) extend this all the way to multiple
extraction

---------

Co-authored-by: atlas <email@atlasdostal.com>
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
@Zeophlite Zeophlite mentioned this pull request Jul 7, 2026
@Zeophlite Zeophlite added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Blocked This cannot move forward until something else changes labels Jul 7, 2026
@Zeophlite
Zeophlite requested review from IceSentry, atlv24, kfc35 and kristoff3r and removed request for kfc35 July 7, 2026 07:36
Comment thread _release-content/migration-guides/extract-extract.md Outdated
pub struct ExtractAppB;

#[derive(Component, Clone, Debug)]
struct RenderComponentSeparateA;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably better named as ExtractComponentSeparateA etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This follows the naming previously in the file, and I think even when moved to bevy_extract its fine to have the example talking about hypothetical "render" components

Comment thread crates/bevy_render/src/extract_plugin.rs Outdated
Comment thread crates/bevy_render/src/extract_component.rs Outdated
Comment thread crates/bevy_render/src/extract_component.rs Outdated
Comment thread crates/bevy_render/src/extract_resource.rs Outdated
@Zeophlite

Copy link
Copy Markdown
Contributor Author

@kfc35 I've updated based on your review, this has made #22852 similar, thank you so much

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-Code-Quality A section of code that is hard to understand or change M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants