Music loops in Godot 4 with no code (WAV loop points + one import setting to watch out for)

Most of the advice I see for looping music in Godot is either “tick Loop” (so the whole file repeats, tail and all) or splitting the track into intro/loop files and switching between them with a script. There’s an easier option that doesn’t get mentioned much.

Godot reads loop points that are stored inside a WAV file. If your WAV has a loop start and loop end saved in it, you drop it into the project, play it on a normal AudioStreamPlayer, and it loops between those two points. If the loop start isn’t at zero, the part before it plays once as an intro and then the loop repeats. The jump back is sample-accurate, so if the loop is clean you won’t hear it.

The catch is the Loop Mode setting in the Import dock. It defaults to “Detect From WAV”, which is what reads the loop points. If you change it to “Forward” (which sounds like the right choice for a loop), Godot ignores the points in the file and loops the whole thing from start to end instead. If your loop suddenly has a gap or a jump, check that setting, put it back on Detect From WAV and hit Reimport.

A few other gotchas:

  • In my testing Godot 4.7 wouldn’t open a 24-bit WAV, so export your music at 16-bit (or use OGG).
  • OGG only has a Loop checkbox and a loop offset you type in by hand. There’s no loop end, so the OGG has to stop exactly where the loop ends.
  • A loop like this can’t let a reverb tail ring over the loop point, because it just jumps back. If the tail matters, you can mix the tail into the start of the file before you export, or play the music on two players so the old pass rings out while the new one starts.

To get loop points into a WAV you need an editor that writes them (they’re usually called sampler loop or smpl loop markers).

I’m a game composer and I ended up making a Windows tool for this part, called Loopsmith. It finds a loop point, lets you listen to the seam, keeps the reverb tail ringing over the loop, and exports a WAV for Godot with the loop points already in it. It can also write a Godot player script if you need an intro and ending, layers, switching between music states, or beat/bar signals. There’s a free demo here if anyone wants to try it: Loopsmith: Game-ready seamless loops by austinhaynes

I also wrote up the WAV loop point stuff in more detail here: https://www.austinhaynesmusic.com/godot-wav-loop-points

If anyone’s fighting with music loops in Godot, feel free to ask, whether you use the tool or not.

1 Like