Skip to content

Fix AtmosphereEnvironmentMap handling - #25699

Open
JMS55 wants to merge 4 commits into
bevyengine:mainfrom
JMS55:atmosphere-extract-fixes
Open

Fix AtmosphereEnvironmentMap handling#25699
JMS55 wants to merge 4 commits into
bevyengine:mainfrom
JMS55:atmosphere-extract-fixes

Conversation

@JMS55

@JMS55 JMS55 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Objective

  • Fix inserting and then removing AtmosphereEnvironmentMap leaving behind AtmosphereEnvironmentMap, GeneratedEnvironmentMapLight, and EnvironmentMapLight.

Solution

  • Use on insert/remove observers to manage the other components needed for AtmosphereEnvironmentMap
  • Also slightly cleaned up prepare_probe_textures (still does the same thing)

Testing

  • Tested in an example by toggling the atmosphere and related components on/off. Before it would leave components hanging around, now it properly cleans up.

@JMS55 JMS55 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 Sep 5, 2026
@JMS55
JMS55 requested a review from mate-h September 5, 2026 23:11
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Sep 5, 2026
@JMS55
JMS55 requested review from Zeophlite and kfc35 and removed request for kfc35 September 5, 2026 23:11
mut commands: Commands,
) {
// Get the first view entity's textures to borrow
let Some(view_textures) = view_textures.iter().next() else {

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.

I know this is what the previous code was doing, but why not use .single()? And if we can't use .single() then what happens if there's more than one view_texture?

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 uhh, couldn't say lol. Single would throw an error if there's more than 1, which, maybe there could be? Idk.

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.

.single() would fail with two cameras that have AtmosphereSettings. Also I think this can be on a LightProbe, which doesn't have its own AtmosphereTextures -- I think this is the correct/only option

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.

To be clear, I get that it would throw an error. I was more wondering about what it should be doing if there's more than one because the current code seems wrong? Like, should it at least print a warning or something?

..Default::default()
});
if already_added_env_map {
entity.remove::<(

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.

I'm a bit confused by this. You're removing these components but then adding them back with the new values? Is that remove necessary? Isn't the end result going to be the same?

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.

This handles reinserting a different amosphere env map (e.g. a different size) on the same entity.

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.

Added a comment

@JMS55
JMS55 requested a review from IceSentry September 5, 2026 23:30
Comment thread crates/bevy_pbr/src/atmosphere/environment.rs Outdated
Comment thread crates/bevy_pbr/src/atmosphere/environment.rs Outdated

@IceSentry IceSentry left a comment

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.

+1 on the try_remove suggestions. I still feel like the .iter().next() thing is a bit weird but it's out of scope for this PR to solve.

LGTM

JMS55 and others added 2 commits September 5, 2026 17:10
Co-authored-by: Stuart Parmenter <pavlov@pavlov.net>
Co-authored-by: Stuart Parmenter <pavlov@pavlov.net>
@JMS55 JMS55 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 Sep 6, 2026
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 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: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants