Enable AudioServer bus effect if no other effect is currently playing

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

TL;DR - I want to enable a reverb effect when my player is underground but not effect any currently playing sounds.

I have a simple platformer and sometimes the player goes underground. So when the player’s Y position is at the right place I do the following

AudioServer.set_bus_effect_enabled(bus_effects, 0, true)

This works pretty good. The issue is if my player makes a sound while on one side of the position check, then goes to the other side, the effect is changed mid way through. So, for example, if my player jumps while inside the cave, but lands outside, the echo of the jump gets cut off and it sounds weird. I did Find this question but in testing this method out I found that the reported volume levels when an effect wasn’t playing were not always -200. In fact, they weren’t always even the same value. So I don’t think that’s reliable way of checking if a sound is playing. Any thoughts would be greatly appreciated.

Thanks All!!

if my player jumps while inside the cave, but lands outside, the echo of the jump gets cut off and it sounds weird.

Can you make the sound hold until the player character is outside of the cave? Until the player is outside the cave, have the echo sound effect in place.

Ertain | 2020-07-18 03:17

That’s what I would like to do. Now, once the player leaves the cave area, the effect is turned off, but that change is applied in real time, so any sounds still playing now have the effect removed, and it works in reverse too. making a sound outside the cave area starts without an echo, but once you cross into the cave, the echo is applied. After more thinking about it all day, I’m wondering if i can maybe poll all the AudioStreamPlayer2D nodes to see if they are playing, and if so, don’t apply the effect until they are all stopped.

Nautic | 2020-07-18 06:37

:bust_in_silhouette: Reply From: Nautic

OK, got it working. If anyone knows a better way please let me know.
I simply created a separate bus for the echo effect and piped it through the main effects bus so that my volume control code didn’t have to be redone. I did have to rewrite how I play effect by adding a simple check to see if I’m underground, but that wasn’t too hard. Now, when i jump outside a cave, the sound plays through the normal bus and if I go into the cave and play a sound the new sound goes over the echo bus, so both can play at the same time without one effect or the other canceling the other out. I’m pretty happy with the results.