bevy/crates/bevy_core_pipeline/src
Kristoffer Søholm 2d1b4939d2
Synchronize removed components with the render world (#15582)
# Objective

Fixes #15560
Fixes (most of) #15570

Currently a lot of examples (and presumably some user code) depend on
toggling certain render features by adding/removing a single component
to an entity, e.g. `SpotLight` to toggle a light. Because of the
retained render world this no longer works: Extract will add any new
components, but when it is removed the entity persists unchanged in the
render world.

## Solution

Add `SyncComponentPlugin<C: Component>` that registers
`SyncToRenderWorld` as a required component for `C`, and adds a
component hook that will clear all components from the render world
entity when `C` is removed. We add this plugin to
`ExtractComponentPlugin` which fixes most instances of the problem. For
custom extraction logic we can manually add `SyncComponentPlugin` for
that component.

We also rename `WorldSyncPlugin` to `SyncWorldPlugin` so we start a
naming convention like all the `Extract` plugins.

In this PR I also fixed a bunch of breakage related to the retained
render world, stemming from old code that assumed that `Entity` would be
the same in both worlds.

I found that using the `RenderEntity` wrapper instead of `Entity` in
data structures when referring to render world entities makes intent
much clearer, so I propose we make this an official pattern.

## Testing

Run examples like

```
cargo run --features pbr_multi_layer_material_textures --example clearcoat
cargo run --example volumetric_fog
```

and see that they work, and that toggles work correctly. But really we
should test every single example, as we might not even have caught all
the breakage yet.

---

## Migration Guide

The retained render world notes should be updated to explain this edge
case and `SyncComponentPlugin`

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Trashtalk217 <trashtalk217@gmail.com>
2024-10-08 22:23:17 +00:00
..
auto_exposure Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
blit Refactor App and SubApp internals for better separation (#9202) 2024-03-31 03:16:10 +00:00
bloom Fix floating point math (#15239) 2024-09-16 23:28:12 +00:00
contrast_adaptive_sharpening Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
core_2d Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
core_3d Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
deferred Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
dof Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
fullscreen_vertex_shader
fxaa Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
motion_blur Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
oit Fix oit webgl (#15728) 2024-10-08 14:50:35 +00:00
post_process Start a built-in postprocessing stack, and implement chromatic aberration in it. (#13695) 2024-07-15 13:59:02 +00:00
prepass Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
skybox Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
smaa Rename rendering components for improved consistency and clarity (#15035) 2024-09-10 01:11:46 +00:00
taa Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
tonemapping Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
upscaling Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
lib.rs Fix oit webgl (#15728) 2024-10-08 14:50:35 +00:00
msaa_writeback.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00