Synchronize removed components with the render world#15582
Synchronize removed components with the render world#15582alice-i-cecile merged 16 commits intobevyengine:mainfrom
Conversation
|
I'll add and update documentation if we decide this is the solution we want |
Trashtalk217
left a comment
There was a problem hiding this comment.
Broadly in favour of this, but there's one big exception that would break this system. This is exceedingly rare, but it does need to be documented.
Say that we have two synced and extracted components A and B. That are located on the same entity.
| Main World | Render World |
| -----------------------------|----------------------------|
| e1: (A, B, RenderEntity(e2)) | e2: (A, B, MainEntity(e1)) |
If you now remove A from e1, this will remove both A and B in the render world.
| Main World | Render World |
| -----------------------------|---------------------------|
| e1: (B, RenderEntity(e2)) | e2: (MainEntity(e1)) |
This may not be what the user expects. And while this scenario may be very rare, it should be documented. You could solve this by counting the number of synced components a entity has (and storing it with SyncToRenderWorld), but that might be a step to far.
Also some documentation is still required for the sync_component plugin.
Trashtalk217
left a comment
There was a problem hiding this comment.
Last couple nits, after this it's ready to go.
|
There are still a few open questions:
Also it looks like some of the examples broke when I merged main, I'll have to debug that later. |
Yes.
Yes. Document this on |
|
@alice-i-cecile seems to work now, tested with a bunch of different examples. It has a tendency to break because of the required component migrations, so I hope we can get it in soon. |
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.
SpotLightto 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 registersSyncToRenderWorldas a required component forC, and adds a component hook that will clear all components from the render world entity whenCis removed. We add this plugin toExtractComponentPluginwhich fixes most instances of the problem. For custom extraction logic we can manually addSyncComponentPluginfor that component.We also rename
WorldSyncPlugintoSyncWorldPluginso we start a naming convention like all theExtractplugins.In this PR I also fixed a bunch of breakage related to the retained render world, stemming from old code that assumed that
Entitywould be the same in both worlds.I found that using the
RenderEntitywrapper instead ofEntityin 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
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