Blog

Games guide

How to make AI game music loop seamlessly in Unity, Godot and the web

7 min read·Oct 6, 2026

Get level music that loops without a click or a gap: how to prompt for loopable tracks, find the loop point by BPM, trim with FFmpeg and set loops in Unity and Godot.

01Why generated tracks do not loop on their own

Most generated tracks are written like songs: an intro, a development and an ending. Played on repeat, the ending crashes into the intro. You fix it in two steps: ask for a track that is easy to loop, then cut it on a bar line. If you still need the track itself, start with the AI game music generator.

02Prompt for loopability

  • Give an exact tempo
    "exactly 120 BPM". It makes the bar length predictable.
  • Ask for a steady groove
    "steady, no tempo changes, no big ending".
  • Avoid dramatic structure words like climax, finale or fade out.
prompt 1

Exploration music for a fantasy forest level, harp and flute over a soft drone, exactly 100 BPM, steady, no big ending, no fade out, instrumental, loopable.

03Find the loop point with math

One bar in 4/4 lasts 240 ÷ BPM seconds. At 100 BPM a bar is 2.4 s, so 16 bars last 38.4 s. Skip the intro (often 2 or 4 bars), then cut a section whose length is a whole number of bars. Start and end on the same chord, and the loop is invisible.

  • 90 BPM
    2.667 s per bar, 16 bars = 42.67 s.
  • 100 BPM
    2.4 s per bar, 16 bars = 38.4 s.
  • 120 BPM
    2 s per bar, 16 bars = 32 s.
  • 140 BPM
    1.714 s per bar, 16 bars = 27.43 s.

04Trim it with FFmpeg

This cuts 16 bars at 100 BPM after a 4-bar intro (9.6 s) and exports OGG for the engine:

copy

ffmpeg -i forest.mp3 -ss 9.6 -t 38.4 -c:a libvorbis -q:a 6 forest_loop.ogg

05Set the loop in your engine

  • Godot 4
    select the file, open the Import tab, enable Loop (and a Loop Offset if you kept an intro), then Reimport.
  • Unity
    tick Loop on the AudioSource. For intro + loop, schedule the loop clip with AudioSource.PlayScheduled at the exact end time of the intro.
  • Web Audio API
    set source.loop = true and use loopStart / loopEnd in seconds. HTML <audio loop> often leaves a small gap with MP3.

06Avoid the click

If you hear a tiny click at the seam, the waveform is not at zero there. Move the cut a few milliseconds, or add a 5–10 ms crossfade in your editor. OGG is also better than MP3 for loops, because MP3 encoders add a small silence at the start of the file.

🔁 “ambient” tracks you can use now15

Dusk Beacon
Vocal1:16
Dusk Beacon
by Ander
Dark cinematic horror ambience inside an abandoned spa. Deep horror soundtrack, ambient
Instrumental3:00
Subterranean Pressure Dark Electronic Horror, Industrial Ambient, Deep Sub-Bass, Cinematic Tension
Instrumental3:10
Subterranean Pressure
Dark Electronic HorrorIndustrial Ambient
Omnipresent Dread Dark Electronic Horror, Industrial Ambient, Deep Sub-Bass, Cinematic Tension
Instrumental3:04
Omnipresent Dread
Dark Electronic HorrorIndustrial Ambient
Analog Dreams ambient, dreamy, cinematic, vintage, trap
Vocal3:27
Analog Dreams
ambientdreamy
VOIDGATE Threshold
Instrumental2:52
8-bit Adventure chiptune, 8-bit, loopable, ambient
Instrumental1:33
8-bit Adventure
chiptune8-bit
Deep Focus Ambient ambient, meditation, calm, pads
Instrumental3:39
Deep Focus Ambient
ambientmeditation
Station Zero Ambience sci-fi ambient, space, synth pads
Instrumental3:23
Station Zero Ambience
sci-fi ambientspace
Abandoned Chapel horror ambient, dark, bells, drones
Instrumental3:29
Abandoned Chapel
horror ambientdark
Subterranean Pressure (alt take) Dark Electronic Horror, Industrial Ambient, Deep Sub-Bass, Cinematic Tension
Instrumental3:18
Subterranean Pressure (alt take)
Dark Electronic HorrorIndustrial Ambient
Omnipresent Dread (alt take) Dark Electronic Horror, Industrial Ambient, Deep Sub-Bass, Cinematic Tension
Instrumental3:03
Omnipresent Dread (alt take)
Dark Electronic HorrorIndustrial Ambient
Deep Focus Ambient (alt take) ambient, meditation, calm, pads
Instrumental3:34
Station Zero Ambience (alt take) sci-fi ambient, space, synth pads
Instrumental3:34

Keep reading

TRY IT IN CLAUDE.

Connect SunoBoard in one minute (free plan included), or browse ready-made tracks first.