UnlockSFX
Guide · Godot 4

How to add sound effects in Godot 4.

Playing a sound in Godot takes one node and one line of code. Making it sound good takes a few more steps: the right player for the job, import settings for loops, variation so repeats don't grate, and buses so players can turn effects down. This guide covers all of it in GDScript, for Godot 4.

The short answer

  • Add an AudioStreamPlayer node, drag your sound into its Stream property, and call play().
  • Use AudioStreamPlayer2D or 3D for sounds that come from a place in the world.
  • Raise max_polyphony so a sound can overlap itself instead of cutting off.
  • Use an AudioStreamRandomizer for variety: several takes plus a little random pitch.
  • Route effects through an SFX bus so players get a volume slider.

1. Pick the right player node

Godot has three audio player nodes. They share the same core properties (stream, volume_db, pitch_scale, bus, max_polyphony) and differ in whether the sound has a position in the world.

AudioStreamPlayer

Sounds with no position: UI clicks, music, menu sounds, a narrator.

Plays at the same volume and pan everywhere.

AudioStreamPlayer2D

2D games: an enemy off to the left, a coin across the screen.

Pans and gets quieter with distance from the camera or listener.

AudioStreamPlayer3D

3D games: footsteps behind you, an explosion down the street.

Positional, with distance falloff and optional doppler.

2. Import your sounds with the right settings

Drop audio files anywhere in your project (a res://sfx/folder keeps things tidy) and Godot imports them automatically. Select a file and open the Import dock to change how it's handled.

  • Short effects:keep them as WAV. The Godot docs recommend WAV for short, frequently repeated sounds because it's cheap to play back.
  • Music and long ambience: use OGG (Vorbis). The files are much smaller.
  • Looping a WAV: set Loop Mode to Forward, then click Reimport.
  • Looping an OGG or MP3: tick Loop, then Reimport.

3. Play a sound from code

Add an AudioStreamPlayer as a child of your player scene, name it JumpSound, and drag your file onto its Stream property in the Inspector. Then call play() when the action happens:

extends CharacterBody2D

@onready var jump_sound: AudioStreamPlayer = $JumpSound

func jump() -> void:
	velocity.y = -400.0
	jump_sound.play()

You can also set the stream in code, which is handy when one player handles several sounds:

jump_sound.stream = preload("res://sfx/jump.wav")
jump_sound.play()

4. Let sounds overlap

By default a player handles one sound at a time: max_polyphony is 1, so calling play()again restarts the sound instead of layering it. That's why rapid gunfire or footsteps can sound choppy. Raise it so several copies can ring out at once:

$ShootSound.max_polyphony = 4

Or set Max Polyphony in the Inspector. Three or four is plenty for most effects.

5. Add variation with AudioStreamRandomizer

Hearing the exact same footstep a hundred times makes a game feel cheap. Godot's AudioStreamRandomizerfixes that: it holds several takes, picks one each time, and can nudge the pitch and volume. In the Inspector, set a player's Stream to a new AudioStreamRandomizer, add your takes, and set:

  • Playback Mode: leave it on the default, which picks at random but avoids playing the same take twice in a row.
  • Random Pitch: about 1.05 to 1.1. A value of 1 means no change.
  • Random Volume Offset dB: 1 or 2.

The same thing in code:

var steps := AudioStreamRandomizer.new()
steps.playback_mode = AudioStreamRandomizer.PLAYBACK_RANDOM_NO_REPEATS
steps.random_pitch = 1.08
steps.random_volume_offset_db = 2.0
for path in ["res://sfx/step_1.wav", "res://sfx/step_2.wav", "res://sfx/step_3.wav"]:
	steps.add_stream(-1, load(path))
$Footsteps.stream = steps

Three to five takes is the sweet spot for anything the player hears constantly: footsteps, hits, pickups, gunshots.

6. Route effects through an SFX bus

Open the Audio panel at the bottom of the editor and add two buses under Master: Music and SFX. Set each sound effect player's bus property to SFX. Now you can change the volume of every effect at once, and add effects like reverb to the whole group.

A volume slider (a HSlider from 0 to 1, step 0.01) is then one line:

func _on_sfx_slider_value_changed(value: float) -> void:
	AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), linear_to_db(value))

Dragging the slider to 0 gives negative infinity decibels, which is silence, so you get a mute for free.

7. Play sounds from anywhere with an autoload

Giving every coin and enemy its own player gets messy, and a sound stops the moment its node is freed. A small autoload that owns a pool of players solves both. Save this as sfx.gdand add it under Project → Project Settings → Globals → Autoload (just "Autoload" in versions before 4.3) with the name Sfx:

extends Node

const VOICES := 8
var _players: Array[AudioStreamPlayer] = []
var _next := 0

func _ready() -> void:
	for i in VOICES:
		var player := AudioStreamPlayer.new()
		player.bus = "SFX"
		add_child(player)
		_players.append(player)

func play(stream: AudioStream, pitch_range := 0.0, volume_db := 0.0) -> void:
	var player := _players[_next]
	_next = (_next + 1) % VOICES
	player.stream = stream
	player.volume_db = volume_db
	player.pitch_scale = 1.0 + randf_range(-pitch_range, pitch_range)
	player.play()

Now any script can fire a sound and safely free itself straight after:

const COIN := preload("res://sfx/coin.wav")

func _on_body_entered(_body: Node2D) -> void:
	Sfx.play(COIN, 0.05)
	queue_free()

This pool is for non-positional sounds. For sounds that need a position, keep an AudioStreamPlayer2D or 3D on the object, or extend the pool with positional players.

8. Positional audio in 2D and 3D

AudioStreamPlayer2D pans and fades sounds by their distance from the listener. Its max_distance sets how far away it can still be heard, and attenuationcontrols how quickly it fades. In 3D, AudioStreamPlayer3D's unit_size sets how far a sound carries before it starts to fade, and max_distancecuts it off entirely. Keep positional sounds mono: a stereo file can't be placed convincingly in space.

Common problems and fixes

The sound cuts off when it plays again quickly

A player plays one sound at a time by default (max_polyphony is 1), so a new play() restarts it. Raise max_polyphony to 3 or 4.

A pickup sound never plays

If you call play() and then queue_free() on the same object, the player is freed with it. Play the sound from a manager that outlives the object (see the autoload below).

There's a click or gap at the loop point

Turn looping on in the Import dock rather than calling play() again on finished. For WAV, set Loop Mode to Forward; for OGG or MP3, tick Loop. A clean loop also needs a file that loops seamlessly.

A positional sound is silent or far too quiet

For 2D, check max_distance (sounds beyond it are silent). For 3D, raise unit_size so the sound carries further, and make sure the scene has a current camera or AudioListener3D.

The same sound gets annoying

Use an AudioStreamRandomizer with 3 to 5 takes, a random pitch around 1.05 to 1.1, and its default no-repeats playback mode.

Where to get the sounds

For prototyping, free CC0 packs like Kenney's are great and need no credit. Other free libraries mix licenses, so check what you're allowed to ship before you use them. Not sure which sounds you still need? Work through the sound effects checklist.

If you'd rather make exactly the sound you need, the UnlockSFX Godot plugin generates royalty-free sound effects from a text description inside the editor. It can make a variation bank of 2 to 8 takes and saves it as a ready-made AudioStreamRandomizer, so step 5 is done for you. It also makes seamless loops for ambience, and right-clicking a folder in the FileSystem dock generates a sound straight into it (Godot 4.3 and newer). For retro blips and UI sounds, there's Forge, our offline, no-AI sound maker.

FAQ

How do I play a sound effect in Godot 4?

Add an AudioStreamPlayer (or the 2D or 3D version) to your scene, set its Stream to your audio file, and call play() on it from a script, for example $JumpSound.play(). For sounds from many different objects, use a small autoload that owns a pool of players.

Should I use WAV or OGG for sound effects in Godot?

The Godot docs recommend WAV for short, frequently repeated sound effects and Ogg Vorbis for music, speech, and long sounds. MP3 is an option for mobile and web projects where CPU time matters.

How do I make a volume slider for sound effects in Godot?

Create an SFX bus in the Audio panel and set each effect's bus property to it. Then connect a 0 to 1 slider to AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), linear_to_db(value)).

How do I randomize sound effects in Godot?

Use an AudioStreamRandomizer as the player's stream. Add several takes, keep the default playback mode (random, avoiding repeats), and set random_pitch slightly above 1 (around 1.05 to 1.1) and random_volume_offset_db to 1 or 2.

Why does my sound stop when the node is freed?

An AudioStreamPlayer stops when it leaves the scene tree. If a coin plays its sound and then frees itself, the sound dies with it. Play it from an autoload sound manager, or hide the object and free it when the player's finished signal fires.

Generate sounds without leaving Godot

The free UnlockSFX plugin turns a text description into a royalty-free sound effect in your project. Your first 3 sounds are free.