Skip to content

Re-add Out to ExtractComponent#23334

Merged
alice-i-cecile merged 7 commits intobevyengine:mainfrom
beicause:extract-component-out
Mar 28, 2026
Merged

Re-add Out to ExtractComponent#23334
alice-i-cecile merged 7 commits intobevyengine:mainfrom
beicause:extract-component-out

Conversation

@beicause
Copy link
Copy Markdown
Contributor

@beicause beicause commented Mar 12, 2026

Objective

Fixes #22863. Fixes #22999. Fixes #23142.

Solution

  1. Re-add Out type to ExtractComponent. Rename SyncComponent::Out to SyncComponent::Target, which is used to clean up components when removing, so that the output of extraction can be different from SyncComponent::Target.
  2. Add #[extract_component_sync_target] attribute for #[derive(ExtractComponent)] to specify SyncComponent::Target.

Testing

Tested ssr and order_independent_transparency examples.
There may be other places where derived components need to be cleaned up, but finding them is somewhat challenging.

@kfc35 kfc35 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 Mar 12, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Mar 12, 2026
@alice-i-cecile alice-i-cecile added the P-Regression Functionality that used to work but no longer does. Add a test for this! label Mar 12, 2026
@alice-i-cecile alice-i-cecile added this to the 0.19 milestone Mar 12, 2026
@alice-i-cecile alice-i-cecile requested a review from atlv24 March 12, 2026 18:11
Copy link
Copy Markdown
Contributor

@kristoff3r kristoff3r left a comment

Choose a reason for hiding this comment

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

This looks like a good approach, and roughly in line with what I was thinking of for future work when I did the SyncComponent trait.

A couple of things to consider:

  • The type Out was named because it was the output type of the extract method, but we might be able to come up with a better name. I think of extraction as taking a component from the main world, based on that we directly produce some components in the render world, and then systems in the render world might additionally produce more. Maybe those can be called derived components? It would be nice to have some terminology for this and use it in the traits.
  • If we no longer use Out in SyncComponent, we can either split the traits (i.e. have ExtractComponent<F = ()>: Component instead of ExtractComponent<F = ()>: SyncComponent<F>), or we can double down and have SyncComponent use both Out and Target for removal. I kinda like the second option but I haven't thought too much about it yet.

Those aren't necessarily blockers for this as this is a decent incremental improvement, but we might as well try to improve things.

Also this will massively collide with #22852. We should make a decision about which one we want merged first.

@beicause
Copy link
Copy Markdown
Contributor Author

Also fixed #23142 by removing both Bloom and Hdr components in transmission example.

But there is still an issue with ExtractComponent::QueryFilter: if an entity's component is extracted and then filtered out by ExtractComponent::QueryFilter in the next frame (e.g. Hdr is removed or Camera is removed), the extracted components cannot be cleared.

@Zeophlite
Copy link
Copy Markdown
Contributor

Also this will massively collide with #22852. We should make a decision about which one we want merged first.

Definitely this one should merge first

if input.just_pressed(KeyCode::KeyH) {
if hdr {
commands.entity(camera_entity).remove::<Hdr>();
commands.entity(camera_entity).remove::<(Bloom, Hdr)>();
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.

If I understand correctly, this does mean that the Out change doesn't really fix this issue. I'm in favor of this PR as a whole, but this is kinda papering over this specific problem imo. This is caused by required components, right?

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.

I think this issue is actually related to QueryFilter, not required component.

Bloom will be filtered out and not extracted if Hdr is removed, but the extracted BloomUniforms will still exist. The same applies to other ExtractComponents that use QueryFilter.

Copy link
Copy Markdown
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.

id merge this without the bloom fix hack, and fix the bloom hdr problem with #23543 instead. But both is also good, I just want to make sure we look into the extract filter query problem later, as that is an actual issue that needs solving imo

@atlv24 atlv24 added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Mar 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

@atlv24
Copy link
Copy Markdown
Contributor

atlv24 commented Mar 27, 2026

Can you also update the migration guide that removed Out this cycle so that we're not claiming it was removed when we actually added it back please?

@alice-i-cecile alice-i-cecile 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 Mar 27, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 28, 2026
Merged via the queue into bevyengine:main with commit 5c36ecf Mar 28, 2026
38 checks passed
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in Rendering Mar 28, 2026
@beicause beicause deleted the extract-component-out branch March 28, 2026 04:35
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 M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

7 participants