Initiation à Godot



Using sound in the game will do a lot in the game experience and using sounds in Godot is quite simple.

Import sounds

Use the  Import > Audio sample menu. You will get a window that let you define the file you want to import, the path you want to store the new resource and also the options applied to the import process. Most of these options aim to increase the game efficiency, generally opposed to sound quality as we’ll see later.

// img

When done, a new smp file id added to the project filesystem.

// img

If you are looking for sample and sound library, have a look at, or

Play sounds

When you want to use your sounds in your projects, you’ll need to make a difference between sound effects, and audio streams, like background music.

Audio streams

In the case of audio streams, you will need a streamPlayer node.

  1. In the Inspector Choose the class for the file you imported in the Stream property.
  2. Then go back to that menu and choose Load. Just select the file you imported.
  3. To automatically play the file, just check the autoplay option in the inspector.

// img

If you want to provide the sound with a script, just attach a script to the node and add this :

 extends StreamPlayer
 func _ready():

This will certainly be the best choice if you want the stream be related to a game option. If you want to change the stream during the game you can load it

 song2 = load("song2.ogg")

and then set it with your player’s set_stream() method before playing it


Sound effects

In the case of sound effect, you will have more things to set. You will have choice between samplePlayer / samplePlayer2D / samplePlayer3D nodes. The first is the most basic, but the two others give stereo effects based on sound position on scene. For those sounds, it’s a good choice to use .wav files.

  1. In the Inspector, you will have to configure the sample Library to make those resources available. In the Config part of the properties, look at Samples and choose New SampleLibrary.
  2. Go there again and choose  Edit which display the sampleLibrary.
  3. There, click on the Open icon and choose the file imported.
  4. From here, you can see the sound properties, can play it for preview and change its name.

You will then need to attach the sound to an event in a script file that will play the sound :


Here, sound is the name of the node and hit the name of the sound resource as defined in sampleLibrary.

If you need to play several sounds at once, set the Config / Voices properties in the Inspector so that each sound owns its one.

If you want to deal more with the sounds especially sets the volume, you will have to attribute your play event to a variable, and then use this variable as the first parameter of the  set_volume method.

 var sound = get_node("sound")
var id ="hit")
id.set_volume(id, 0.5)

Import options and sound design opportunities

File Formats

But using sound isn’t as simple is could appear. You may have seen that we told «import the .wav file». What’s this antic format ?! In fact, most of the sounds used nowadays are compressed sounds, like mp3 or ogg. That’s why there are interesting for online music : downloading them is fast and you don’t need a huge storage to keep them. Here we could say : «cool ! my game will be lighter without doing any efforts».

Unfortunately, compress means on the other hand uncompress. So, using compressed formats in the game will result in a need to uncompress at runtime, before playing game. In practice this will increase the amount of calculation done by the engine and slow down the game. Remember that the game engine needs to maintain plenty of other calculations and that it is never a good idea to count on the engine effort without evaluation.

For sound effects, it’s important the sound plays as quickly as possible to avoid delay. Use .wav.

For audio streams, there is no need to have the whole file in memory to be played and delay won’t be a problem because those sounds are not related to game interaction. In this case OGG or MPC will be good choice for Godot. Files can be convert with audacity if needed.

Effects and silences

We can say the same about sound creation. Adding effects to sounds, like reverb, will enlarge the file size and in the same time the effort need to render. It’s not a bad idea to begin with simple sounds, and, when the game production reaches the end, see if there is opportunity for better resources. In that purpose, sfx artists should be aware to always keep the source files to update the game resources from a good quality original. To avoid, problem involved by such effects, Godot includes a reverb generator adapted to game rendering, that can be setup with a four-step range.

An other point in which savings can be done is trimming. In many sounds there will be a portion of silence at the beginning and at the end. The problem of the sounds is that they will be delay when played. Cutting the sound so that only the significant part in kept will make things clearer when delay will need to be set. This will eventually be a question of settings or scripting in the engine and there won’t be no need to edit the sound for other results.

It will be a designer choice to know when to put the effort in Godot effects and when it should be done with a sound editor.


Some other saving can be done in quality. Most of time, sound are stereo with a high sampling rate such as 96khz. In fact, using 44khz mono will drastically reduce size file memory efforts. Generally, for most use cases, the difference won’t be audible to users. So it would be a good choice to downsample sounds if possible.

Sound artist will often be disappointed by this approach, because it’s an opposite position that they will have learned. They’ll feel like limited and that they can’t give the best. Anyway, it’s important to keep in mind that a game is a whole and that visual artist would also like to have high-resolution images, 3D artists high poly meshes, and so on. From this point of view the game is still a compromise, the most important being fluency and playing comfort.

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.