Change "global" volume in 3.0

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jobax

Is there a way to change the global volume of all music/sound? Is there also a global way to stop any currently playing music? I can do these manually looping through each AudioStreamPlayer but there has to be a proper way.

It’s for a “master volume” type setting you commonly find in games. I’ve found stuff like this AudioServer.set_stream_global_volume_scale(0) but it doesn’t work for 3.0.

Also is there a way to use variables with $? I can do it with get_node but not $. Not sure how to do it. Thanks.

The thing about $ should really be a separate question. The answer though is that you cannot use variables with $. $ is only for static paths (meaning the path is the same path each time, decided when you write the code).

raymoo | 2018-02-23 01:53

Yeah makes sense. It’s not really an issue, I just wanted to see if I could make the code look cleaner, so I didn’t want to put it in a different question. Thanks.

Also figured out the sound thing, just use bus volume…

jobax | 2018-02-23 02:01

:bust_in_silhouette: Reply From: pgregory

For master volume, something like:

AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), 0)

The “Master” bus is fixed, you cannot rename it, so that should work.

Not sure about a way of “stopping” all currently being played sounds/music, that would imply a global access to all the AudioStreamPlayer nodes. If you really need to stop/start the music, perhaps have a global registry of sound in an auto-loaded class, that you can access from anywhere and turn music on/off. If you just mean muting music, as opposed to stopping it, then I’d recommend routing your music nodes through a separate bus, perhaps called “Music” and then doing:

AudioServer.set_bus_mute(AudioServer.get_bus_index("Music"), true)

I’ve done something similar, routed music through one bus, and SFX through another, which allows me to control volume of each aspect independently.

Thanks yeah. That’s what I figured out. Basically set each type of audio to different buses e.g. sfx, music and then set_bus_mute(0, true) for master volume, set_bus_mute(1, true) for sfx, etc.

jobax | 2018-02-26 03:03