Your game works. It just sounds like nothing. The character jumps in silence, and coins vanish without a ding. Sound is the cheapest way to make a small game feel finished. Godot 4 gives you three player nodes for the job. This post compares all three, then builds one small game, Coin Rush, that uses each of them. Every line of code here was run in Godot 4.3. If you prefer watching, the video version is in the Godot 4 Full Course in Hindi, free on YouTube.
The three players, side by side
Godot splits sound into two ideas: an AudioStream is the sound file, and an AudioStreamPlayer is the node that plays it. The three players share the same settings and differ in one thing only, whether the sound has a place in the world.
| Player | Where the sound comes from | Use it for |
|---|---|---|
| AudioStreamPlayer | Nowhere in particular. Same volume and pan everywhere. | Music, menu clicks, narration. |
| AudioStreamPlayer2D | A point in your 2D scene. It pans and fades with distance. | Coins, footsteps, doors. |
| AudioStreamPlayer3D | A point in 3D space, with distance and direction. | 3D games only. |
Pick by the sound: no location, plain player; a spot on the map, 2D player. Godot's guide to audio streams describes all three with pictures.
The demo: Coin Rush
Everything below comes from one small project called Coin Rush: a Music player, a player character that can run and jump, a coin, and a floor. The music is a four second arpeggio, the coin sound is a two tone ding, the jump sound is a rising sweep. All three are plain WAV files that Godot imported on its own.
Music that plays itself
Music is the easiest win. Add an AudioStreamPlayer to your main scene and name it Music. Drag your music file onto its Stream property in the Inspector. Turn on Autoplay and the track starts when the scene loads. Set volume_db to -12 so the music sits under the effects. Then make it loop: for WAV, set Loop Mode to Forward in the Import dock and click Reimport. For OGG and MP3 there is a Loop checkbox instead. One warning: a looping stream never emits the finished signal, because it never finishes. Looping music usually lives on the title screen, so if you built a main menu in Godot 4, this is the same player on that scene.
A jump sound on cue
The jump sound lives on the player, because the player is the thing that jumps. Add an AudioStreamPlayer as a child of your CharacterBody2D, name it JumpSound, drag the jump file onto Stream, and set its Bus to SFX. Play it in the exact line where the jump happens. Here is the whole script:
extends CharacterBody2D
const SPEED := 220.0
const JUMP_VELOCITY := -420.0
const GRAVITY := 980.0
@onready var jump_sound: AudioStreamPlayer = $JumpSound
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity.y += GRAVITY * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
jump_sound.play()
var direction := Input.get_axis("ui_left", "ui_right")
velocity.x = direction * SPEED
move_and_slide()ui_accept is Space or Enter by default, so this works with no input setup. is_on_floor() stops the sound firing in mid air. The movement follows the same pattern as how to move a character in Godot 4 with GDScript. One catch: calling play() on a player that is already playing restarts it from the start. Fine for a jump, a problem for rapid coins.
A coin that rings where it sits
Coins are the textbook case for the 2D player. The coin is an Area2D, and its sound is an AudioStreamPlayer2D child of the coin, so the ring comes from where the coin sits. Walk left and the sound leans left; walk away and it gets quieter. The script only says play:
extends Area2D
@onready var coin_sound: AudioStreamPlayer2D = $CoinSound
func _ready() -> void:
body_entered.connect(_on_body_entered)
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player"):
coin_sound.play()
hide()
$CollisionShape2D.set_deferred("disabled", true)
# Wait for the sound to finish before freeing the coin.
# queue_free() right away would kill the player node too,
# because CoinSound is a child of the coin.
await coin_sound.finished
queue_free()body_entered is a signal, so the coin reacts the moment something touches it; how Godot signals work explains the pattern in full. The player has to sit in the "player" group. The coin is hidden and its collision switched off before the sound ends, so it can never trigger twice. The classic beginner bug is freeing the coin at once, which also frees its child player node and kills the ding halfway. Wait for finished first.
Stop every footstep sounding identical
The same footstep a hundred times makes a game feel cheap. AudioStreamRandomizer fixes that: it holds a pool of clips, picks one each time it plays, and nudges the pitch and volume a little.
var steps := AudioStreamRandomizer.new()
steps.add_stream(0, preload("res://sfx/step.wav"))
steps.add_stream(1, preload("res://sfx/step2.wav"))
steps.random_pitch = 1.15
$StepSound.stream = stepsA random_pitch of 1.15 means the pitch lands somewhere between 1 divided by 1.15 and 1.15, a small wobble, not a cartoon voice. A value of 1.0 means no variation. The default mode avoids playing the same clip twice in a row. Two or three takes are enough.
One slider for every effect
Sooner or later the player wants a volume slider, and that is where buses earn their keep. Open the Audio panel at the bottom of the editor and add two buses under Master, Music and SFX. Set each player's Bus property to the matching name, and one function turns down every effect at once:
func set_bus_volume(bus_name: String, value: float) -> void:
var bus_index := AudioServer.get_bus_index(bus_name)
if value <= 0.0:
AudioServer.set_bus_mute(bus_index, true)
else:
AudioServer.set_bus_mute(bus_index, false)
AudioServer.set_bus_volume_db(bus_index, linear_to_db(value))linear_to_db turns a slider value between 0 and 1 into decibels: 1.0 is 0 dB, 0.5 is about -6 dB. The if matters because linear_to_db(0.0) is minus infinity, and passing that into set_bus_volume_db is not how you silence a bus. Muting is. A slider from 0 to 1 calls this function on value_changed. Godot's audio buses tutorial shows the bus panel and the routing in full.
WAV or OGG: pick by the job
Godot imports WAV, Ogg Vorbis and MP3. The docs give a plain rule: WAV for short, repeated sound effects, Ogg Vorbis for music, speech and long effects. WAV is cheap for the CPU to play, which is what you want when twenty coins ring at once. OGG files are much smaller but cost more CPU per play, and MP3 sits in the middle, handy for mobile and web. The Import dock can force mono, cap the sample rate and trim silence from the ends of a clip.
When the sound does not play
Nothing plays at all. Check the Stream property first: a player with no stream plays nothing and reports no error.
The sound plays once, then never again. Calling play() while the stream is still playing restarts it. For rapid repeats like coins, raise max_polyphony to 3 or 4 so copies can overlap.
The music stops after one play. The file is not looping. For WAV, set Loop Mode to Forward and click Reimport. For OGG or MP3, tick Loop.
The coin sound cuts off halfway. You freed the coin while its sound was still playing, and the player node dies with its parent. Wait for finished, then free.
Everything is too quiet, or too loud. Check the chain in order: the file's own volume, the player's volume_db, then the bus volume.
Questions beginners ask
Can I play a sound without adding a player node in the editor?
Yes. Create one in code: var player := AudioStreamPlayer.new(), player.stream = preload("res://sfx/coin.wav"), add_child(player), player.play(). Handy for one off sounds, but a named node is easier to find and tune later.
How many sounds can play at once?
More than a first game needs. WAV is cheap on the CPU, and the docs say hundreds of simultaneous voices in that format are fine. OGG costs more per voice, so keep the count modest for compressed files.
Do I need a different player for every sound?
No. One player can swap streams with player.stream = next_sound followed by player.play(), but swapping stops whatever was already playing. One player per repeating event is the simple rule.
Why does my 2D sound not pan?
Check that the sound uses AudioStreamPlayer2D and not the plain player, which has no position to pan from. Then check the sound sits away from the centre of the screen. A coin dead centre plays dead centre, and that is correct behaviour, not a bug.
Your turn
Add one sound to your own game today: a jump, a coin, a click. Then add the second bus and the slider. The next step is the course this series follows, the Godot 4 Full Course in Hindi, free on YouTube.
Leave a Comment