Simple 3D use case: I have a Listener attached to my 3P character and a speaker attached to the environment, providing general background ambience (no attenuation).

When the character goes underwater, I'd like the environmental noise to be muffled and when they enter a building, I'd like echo, etc.

[Edit] In reality I have numerous AudioStreamPlayer3D objects attached to the environment (general ambience, sounds of a stream laid out along its course, sound attached to a NPC) so switching them all from one bus to another on on_body_entered and on_body_exited signals from the Area seems very inefficient, though I know I can probably achieve what I want that way.


Don't move AudioStreamPlayer3D from an audio bus to another. Instead modify the audio bus on runtime. You should only have to modify one or two audio buses when leaving or entering an area. I remind you that usually we have the Master audio bus, and other audio buses routed to Master, but you can route a bus to another instead.

See AudioServer and Audio Buses.

You can get the index of a bus by name like this:

var bus_index = AudioServer.get_bus_index(bus_name);

get_bus_index returns -1 if the bus does not exist.

You can change the volume of the audio bus like this:

AudioServer.set_bus_volume_db(bus_index, db);

You can set the effects you want in the audio bus from the editor, and then enable or disable them like this:

AudioServer.set_bus_effect_enabled(bus_index, effect_index, enabled);

I encourage to set the effects you want in the editor and simply enable or disable them. However, you can also add and remove effects with AudioServer.add_bus_effect and AudioServer.remove_bus_effect respectively. If you are adding and removing audio effects at runtime I suggest to only do one per audio bus, and take advantage of the routing.

Know that AudioEffects are resources. I suggest to export a resource variable from your script where you setup the audio effect:

export(AudioEffect) var audio_effect;

Then you can use the IDE to create the audio effect you want.

  • \$\begingroup\$ Perfect, thanks! I'll give it a try this evening. \$\endgroup\$ – Bill H. Mar 12 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.