Fix the behavior of NoCpuCulling when toggled at runtime.#23534
Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom Mar 28, 2026
Merged
Fix the behavior of NoCpuCulling when toggled at runtime.#23534alice-i-cecile merged 1 commit intobevyengine:mainfrom
NoCpuCulling when toggled at runtime.#23534alice-i-cecile merged 1 commit intobevyengine:mainfrom
Conversation
Currently, adding `NoCpuCulling` to a mesh causes that mesh to disappear. This is due to two bugs: 1. Meshes are unconditionally, and incorrectly, added to `RenderGpuCulledEntities`, even if they are subject to CPU culling. Entities are only added to the GPU culling bucket if they (1) don't participate in CPU culling, (2) are in `RenderGpuCulledEntities` *now*, and (3) weren't in `RenderGpuCulledEntities` *before*. Right now, since entities are always in `RenderGpuCullingEntities`, these conditions are never met. This PR fixes the issue by excluding entities without the `NoCpuCulling` component from `RenderGpuCulledEntities`. 2. The `extract_meshes_for_gpu_building` system tries to extract meshes for which `Changed<NoCpuCulling>` is true, but it fails because the query is written like `Or<(Changed<Foo>, (Changed<Bar>, Changed<NoCpuCulling>))>` instead of `Or<(Changed<Foo>, Or<(Changed<Bar>, Changed<NoCpuCulling>)>)>`. The former is interpreted as `Changed(Foo) || (Changed(Bar) && Changed(NoCpuCulling))` instead of `Changed(Foo) || Changed(Bar) || Changed(NoCpuCulling)`, which was the intention. Because of this, we were failing to extract meshes that had `NoCpuCulling` assigned to them unless they were changed in some other way. This issue was noticed when attempting to add a check box to `bevy_city` to disable CPU culling. I went ahead and added the check box to that example, now that the issue preventing it from working is fixed.
IceSentry
approved these changes
Mar 27, 2026
Contributor
IceSentry
left a comment
There was a problem hiding this comment.
I can confirm it fixed the runtime change in bevy_city. Thanks for adding the checkbox!
Code looks good too.
Contributor
Author
|
I think this obsoletes #23508 |
Contributor
|
Yeah, I'm pretty sure it does. At least this PR fixed everything for me so #23508 doesn't seem necessary |
atlv24
approved these changes
Mar 27, 2026
splo
pushed a commit
to splo/bevy
that referenced
this pull request
Mar 31, 2026
…ne#23534) Currently, adding `NoCpuCulling` to a mesh on a frame after that mesh was spawned causes that mesh to disappear. This is due to two bugs: 1. Meshes are unconditionally, and incorrectly, added to `RenderGpuCulledEntities`, even if they are subject to CPU culling. Entities are only added to the GPU culling bucket if they (1) don't participate in CPU culling, (2) are in `RenderGpuCulledEntities` *now*, and (3) weren't in `RenderGpuCulledEntities` *before*. Right now, since entities are always in `RenderGpuCullingEntities`, these conditions are never met when adding `NoCpuCulling` to an existing mesh that didn't have that component before. This PR fixes the issue by excluding entities without the `NoCpuCulling` component from `RenderGpuCulledEntities`. 2. The `extract_meshes_for_gpu_building` system tries to extract meshes for which `Changed<NoCpuCulling>` is true, but it fails because the query is written like `Or<(Changed<Foo>, (Changed<Bar>, Changed<NoCpuCulling>))>` instead of `Or<(Changed<Foo>, Or<(Changed<Bar>, Changed<NoCpuCulling>)>)>`. The former is interpreted as `Changed(Foo) || (Changed(Bar) && Changed(NoCpuCulling))` instead of `Changed(Foo) || Changed(Bar) || Changed(NoCpuCulling)`, which was the intention. Because of this, we were failing to extract meshes that had `NoCpuCulling` assigned to them unless they were changed in some other way. This PR fixes both of these issues, and also refactors `extract_meshes_for_gpu_building` a bit to reduce rightward drift. This issue was noticed when attempting to add a check box to `bevy_city` to disable CPU culling. I went ahead and added the check box to that example, now that the issue preventing it from working is fixed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, adding
NoCpuCullingto a mesh on a frame after that mesh was spawned causes that mesh to disappear. This is due to two bugs:Meshes are unconditionally, and incorrectly, added to
RenderGpuCulledEntities, even if they are subject to CPU culling. Entities are only added to the GPU culling bucket if they (1) don't participate in CPU culling, (2) are inRenderGpuCulledEntitiesnow, and (3) weren't inRenderGpuCulledEntitiesbefore. Right now, since entities are always inRenderGpuCullingEntities, these conditions are never met when addingNoCpuCullingto an existing mesh that didn't have that component before. This PR fixes the issue by excluding entities without theNoCpuCullingcomponent fromRenderGpuCulledEntities.The
extract_meshes_for_gpu_buildingsystem tries to extract meshes for whichChanged<NoCpuCulling>is true, but it fails because the query is written likeOr<(Changed<Foo>, (Changed<Bar>, Changed<NoCpuCulling>))>instead ofOr<(Changed<Foo>, Or<(Changed<Bar>, Changed<NoCpuCulling>)>)>. The former is interpreted asChanged(Foo) || (Changed(Bar) && Changed(NoCpuCulling))instead ofChanged(Foo) || Changed(Bar) || Changed(NoCpuCulling), which was the intention. Because of this, we were failing to extract meshes that hadNoCpuCullingassigned to them unless they were changed in some other way.This PR fixes both of these issues, and also refactors
extract_meshes_for_gpu_buildinga bit to reduce rightward drift.This issue was noticed when attempting to add a check box to
bevy_cityto disable CPU culling. I went ahead and added the check box to that example, now that the issue preventing it from working is fixed.