Fix confusing comment in pbr example (#16996)

# Objective

After a recent fix for a panic in the pbr example (#16976), the code
contains the following comment:

```rust
// This system relies on system parameters that are not available at start
// Ignore parameter failures so that it will run when possible
.add_systems(Update, environment_map_load_finish.never_param_warn())
```

However, this explanation is incorrect. `EnvironmentMapLabel` is
available at start. The real issue is that it is no longer available
once it has been removed by `environment_map_load_finish`.

## Solution

- Remove confusing/incorrect comment and `never_param_warn()`.
- Make `Single<Entity, With<EnvironmentMapLabel>>` optional in
`environment_map_load_finish`, and check that the entity has not yet
been despawned.

Since it is expected that an entity is no longer there once it has been
despawned, it seems better to me to handle this case in
`environment_map_load_finish`.

## Testing

Ran `cargo run --example pbr`.
This commit is contained in:
Martin Dickopp 2024-12-29 23:45:17 +01:00 committed by GitHub
parent 0f2b2de333
commit 6114347bc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,9 +7,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
// This system relies on system parameters that are not available at start
// Ignore parameter failures so that it will run when possible
.add_systems(Update, environment_map_load_finish.never_param_warn())
.add_systems(Update, environment_map_load_finish)
.run();
}
@ -130,7 +128,7 @@ fn environment_map_load_finish(
mut commands: Commands,
asset_server: Res<AssetServer>,
environment_map: Single<&EnvironmentMapLight>,
label_entity: Single<Entity, With<EnvironmentMapLabel>>,
label_entity: Option<Single<Entity, With<EnvironmentMapLabel>>>,
) {
if asset_server
.load_state(&environment_map.diffuse_map)
@ -139,7 +137,10 @@ fn environment_map_load_finish(
.load_state(&environment_map.specular_map)
.is_loaded()
{
commands.entity(*label_entity).despawn();
// Do not attempt to remove `label_entity` if it has already been removed.
if let Some(label_entity) = label_entity {
commands.entity(*label_entity).despawn();
}
}
}