Skip to content

Move render app init and extraction to separate plugin#22758

Merged
alice-i-cecile merged 11 commits intobevyengine:mainfrom
kristoff3r:ks/extract_plugin
Feb 6, 2026
Merged

Move render app init and extraction to separate plugin#22758
alice-i-cecile merged 11 commits intobevyengine:mainfrom
kristoff3r:ks/extract_plugin

Conversation

@kristoff3r
Copy link
Copy Markdown
Contributor

Objective

Currently in bevy_render the renderer initialization (e.g. creating a surface, registering rendering systems) is very intertwined with setting up the extraction logic itself (e.g. how is data moved between the worlds, how are they kept in sync). This makes it harder to understand both things, and also makes it very hard to test the extraction logic, as you don't want to start the renderer in unit test.

In the future this functionality might even be useful for the ECS outside bevy_render, e.g. for custom renderers that want to use a render world, or for multi world setups.

Solution

This PR splits out creation of the render subapp plus the extraction logic itself into ExtractPlugin, and uses the new found flexibility to finally add a test for it.

This is the first part in a series of PRs I plan to do to:

  • Separate the extraction logic so it's possible to test (this one)
  • Fix the bug that's currently commented out in the test
  • Rework the Extract trait to bypass the orphan rules, so we can use it everywhere (speculative but I have an idea)

Testing

Added a test to show that extraction is working.

I also ran a bunch of examples requiring rendering and they still work.

@kristoff3r kristoff3r added A-Rendering Drawing game state to the screen C-Code-Quality A section of code that is hard to understand or change S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 31, 2026
@alice-i-cecile alice-i-cecile requested a review from atlv24 January 31, 2026 22:06
@alice-i-cecile alice-i-cecile added the A-Windowing Platform-agnostic interface layer to run your app in label Jan 31, 2026
@kristoff3r kristoff3r removed the A-Windowing Platform-agnostic interface layer to run your app in label Feb 1, 2026
@alice-i-cecile alice-i-cecile added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Feb 2, 2026
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I like separating these, and this appears to have been done correctly.

@kristoff3r
Copy link
Copy Markdown
Contributor Author

I disentangled the 2 plugins a bit more, let me know what you think. I haven't worked that much with schedule creation before, and I didn't realize you have to be careful about ordering when doing .add_schedule. I added a warning that would have saved me 30 minutes 😄

Now the only render specific things are the RenderApp label, and that it creates and uses the Render schedule.

kristoff3r and others added 2 commits February 6, 2026 19:14
Co-authored-by: atlv <email@atlasdostal.com>
@atlv24 atlv24 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 6, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 6, 2026
Merged via the queue into bevyengine:main with commit e17721e Feb 6, 2026
44 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Feb 6, 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 #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.~~ edit: the assert has been
added.
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-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants