-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Updating GlobalVolume
now updates the volume of any playing (Spatial)AudioSinks
#19168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
1b2aee6
to
358b26e
Compare
358b26e
to
405fa13
Compare
Might've bitten off a bit more than I can chew here. Looking into the validation failure, it seems like other systems that operation on AudioSinks take |
I'm curious if there's value in Bevy having a Part of the reason is that different types of sounds have their own volume anyway, so the global/master volume setting is only half the equation. For example, I have a music volume setting, sound effect volume setting, conversation volume setting and voice over volume setting. And then each of my sounds can have their own per-sound volume. I have systems like this: app.add_systems(
Update,
update_volume.run_if(resource_exists_and_changed::<SoundConfig>),
);
fn update_volume(sound_config: Res<SoundConfig>, query: Query<(&AudioSink, &SoundEffectSettings)>) {
for (sink, settings) in query.iter() {
sink.set_volume(
sound_config
.sound_effect_volume(Volume::Amplitude(settings.linear_volume() as f64))
.as_amplitude() as f32,
);
}
} Its purpose is to modify currently playing sounds to make their volume update based on the player changing volume settings in the options screen. (Ignore the verbosity of volume linear/amplitude calculation in this system, it's not relevant) But notice that I call
And return the combined volume for that sound. All that is to say, does it make sense for Bevy to have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing a quick little draft-mode review to hopefully get you unstuck.
The big scary ambiguity warning isn't quite as scary as it seems.
Bevy's scheduler will handle keeping the mutable accesses exclusive. CI just wants to make sure that we're either defining an order for systems to run in when we're modifying/accessing something in multiple systems and the order in which it happens is ambiguous.
This can be resolved by either telling Bevy that it's okay for the systems to run in any order (by adding .ambiguous_with(system)
or .ambiguous_with_all()
), or defining an order (by adding .after(system)
, .before(system)
.
After fixing the add_systems
call I mentioned in another comment, you should be left with four ambiguities:
update_playing_audio_volume <-> update_emitter_positions
update_playing_audio_volume <-> update_listener_positions
update_playing_audio_volume <-> cleanup_finished_audio<Pitch>
update_playing_audio_volume <-> cleanup_finished_audio<AudioSource>
At a glance, the particular ordering of these systems doesn't seem super important, so I'd start the conversation by just adding .ambiguous_with_all()
when adding the update_playing_audio_volume
system.
Objective
Fixes #18952
Solution
Adds a system that iterates playing audio sinks and reconfigures the volume if
GlobalVolume
changes. Volume change is based on the initialPlaybackSettings
.Testing
Adjusted game_menu example to play music in the volume screen and actually made that volume slider modify
GlobalVolume
.Showcase
output.webm