Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Why your ambience loop plays once in Godot: a 3-minute import check (with a probe script)

A topic by yetiancai created 15 days ago Views: 179 Replies: 2
Viewing posts 1 to 2
(+1)

Looping audio fails silently in Godot: the file may be perfectly seamless, but the importer decides whether it loops. Here is what I found when I tested some files, plus a short script so you can check your own.


What I tested (Godot 4.7.2 stable, headless, 27 October 2026, default import settings unless stated):

- A 48 kHz / 24-bit stereo WAV with loop markers in the file (an `smpl` chunk) was imported as a Forward loop automatically: `loop_mode = 1`, `loop_end = 2879999`, which is exactly 60 s x 48000 minus 1. The same happened with a second 60 s file.

- A one-shot WAV imported with `loop_mode = 0`, as expected.

- A 44.1 kHz / 16-bit WAV with no loop markers imported with `loop_mode = 0`: it plays once, even though the audio itself loops cleanly. I started two players on it and on a looping file; the first one stopped at 42 s and the other kept going.

- After setting Edit > Loop Mode to Forward in the Import dock and reimporting, the same file read `loop_mode = 1`, `loop_begin = 0`, `loop_end = 1852199` (42 s x 44100 minus 1).

- The matching OGG imported with `loop = false`, `loop_offset = 0`; with Loop ticked it read `loop = true`.

- The default WAV compress mode in 4.7.2 is Quite OK Audio (QOA) according to the docs, and the loop points above still came through with it.


So the checklist:

1. Does the file carry loop markers? If not, set Loop Mode to Forward in the Import dock (WAV), or tick Loop (OGG), then press Reimport.

2. Print the result instead of guessing. Put this in a script and run it with `godot --headless -s probe.gd` from your project folder (change the file names):


extends SceneTree
func _init():
 for f in ["rain_loop.wav", "knock_01.wav"]:
  var s = load("res://audio/" + f) as AudioStreamWAV
  print(f, " loop_mode=", s.loop_mode, " loop_begin=", s.loop_begin, " loop_end=", s.loop_end, " length_s=", s.get_length())
 quit()


3. If you hear a click at the loop point, compare the last and first sample values with the file's normal sample-to-sample steps. A jump bigger than 99% of the normal steps is the likely cause; fix it with a crossfade in your audio editor, not in the engine.


The Godot docs page on importing audio samples covers the same options (Loop Mode for WAV, Loop and Loop Offset for OGG and MP3): https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/importing_audio_samples.html


Question for everyone: have you hit a case where a loop worked in the editor but not in an exported build, or the other way around? I haven't, and I'd like to know what to add to the checklist.


— yetiancai

Useful checklist, thanks, especially the probe script. Printing the import values beats guessing every time.

Two things I'd add from the audio side, for ambience in particular:

1. Wrap the tail. If the loop was rendered with reverb or delay on it, the last bar has a tail that the first bar doesn't, so you get a small dip in density at the loop point even with no click. Render a bit longer than the loop, cut the extra off the end and mix it back over the start, and the seam disappears.

2. Check both channels at the seam. A stereo loop can be smooth on the left and jump on the right, so your 99% step test is worth running per channel.

On formats: in general MP3 encoders add a little padding at the start and end of a file, which is one reason OGG is usually the safer choice for loops. Worth a line in the checklist if you test it in Godot.

I haven't hit an editor-vs-export difference either, so I'm curious if anyone has.

Thanks for these — all three are solid catches, and I just ran them against the actual loops I ship to check myself.

1. Per-channel seam check: you're right that checking L and R separately matters. On my 60 s stereo rain loops (`rain_light_distant_loop.ogg` and `rain_light_outside_loop.ogg` in the Godot doorway sample), the seam jump stayed below the 99th-percentile internal step on both channels, but L and R differed by more than 2x on one file (`0.38x` on L vs `0.16x` on R). Checking mono or only one channel would easily hide a single-channel jump.

2. Tail wrap / density dip: I measured start vs. end RMS across my older 44.1 kHz free loops (`Ambient Loops Free Lite`) and this caught something real on `forest_day_loop.wav` — the sample-level seam jump is tiny (`0.18x` L / `0.27x` R of p99, so no click), yet the last 4 s sits ~6.6–7.1 dB quieter than the first 4 s. `rain_light_loop.wav` stayed within ~0.3 dB over the same 4 s window. So a sample-step check alone really does miss level/tail density drift at the wrap point.

3. MP3 vs. OGG padding: I encoded the same 42.000 s `rain_light_loop.wav` with `ffmpeg` (`libvorbis` vs. `libmp3lame`) and checked `ffprobe`. OGG kept `start_time = 0.000000` and exact `duration = 42.000000 s`; MP3 came out with `start_time = 0.025057 s` (~25 ms encoder delay) and `duration = 42.031020 s` (~31 ms extra container length). I haven't run `AudioStreamMP3` through `probe.gd` in Godot yet, so I'll wait until I test it in-engine before claiming exact Godot behavior, but that padding alone is a good reason to default to OGG (or WAV) for loops.

One small Godot detail I also bumped into while putting the doorway sample together: because default `.ogg.import` writes `loop=false`, setting `stream.loop = true` in `_ready()` on the `AudioStreamOggVorbis` works as a fallback if you want a project to loop out of the box without editing `.import` files.

I'll fold per-channel seam checks and tail-wrap density checks into my loop checklist. Good to hear you haven't hit an editor-vs-export mismatch either.