Topic was automatically imported from the old Question2Answer platform.
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…
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:
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.