How to change sfx volume

I just finished the One-Time sound effects lesson for the godot 4 2D class. However, the jump sound is too loud. Is there a way to change that volume via code?


you an tweak the volume of the audiostream player using its volume_db property.

this property is 0 by default, so probably a -5 would lower it a bit.

just done a quick test and this is how i done it.

since were creating a new audiostreamplayer each time to create the SFX, we would have to set the property each time.

what you can do is have an export variable, just so that you can set it with a slider.
if you pop this at the top of the script

# -- Just to have hints in the inspector --
@export_category("Audio Settings")
var jump_sfx_volume : float = 0 

then just after we create the stream player, or just before we call add_child(asp), we can check to see if its the jump thats being played, if it is, then adjust the volume

 #this is the bit ive added in to set the volume for the player,  
#just for the jump audio
	if stream == jump:
		asp.volume_db = jump_sfx_volume

its just a little trickier with this one, since were only wanting to change the volume for a single SFX rather than the whole audio player.

hope that helps you out.

1 Like

Privacy & Terms