Seamless Music Looping

Hi there, I am having trouble with getting my music in my game to play properly.

The way it currently works is: I have a sound cue that concatenates two tracks together, one representing the first part of the song to play, and then the looping part of the song to play and loop forever. Then I call it when it’s ready to play the cue.

All of this works fine, save for one key issue: when it plays the looping track for the first time, there is a tiny space of silence or “hitch” between the two tracks. I believe this is because it needs to load the second song before it can play, which of course makes sense.

The question is: how does one load a sound into a cue without playing it first, or, is there a better more cleaner way to do this altogether?

Have you figured out how to fix it?

I have not, but this is gonna bother me for the rest of my life. I’m SUPER picky about this stuff in games. I did discover, however, that my initial hypothesis is correct; this is happening because of loading.

One decent solution is to use just one audio file that can be looped on its own without having to load anything else, but then you can’t get music that has a beginning part attached to it.

What if you had the full song, intro and loop merged together as one and have the loop play to get as close as possible to make it sound the same, but with the volume of zero and then raise it to the normal after the whole merged song stopped.

Any news on this? I got the same issue and had to use FMOD plugin to overcome this, however I’d like to use native UE instruments since FMOD is quite big dependency.

Well if you are desperate you can use this technique. It’s not pretty and not perfect, but it kind of fulfill its purpose.

alt text

Hey there fellow human beings, it’s been a while since I’ve responded to this post, but I believe that I have found a suitable solution to this issue. It isn’t 100% perfect, but it’ll have to do for now. This method is largely based on @ExtraTorpedo 's method shown in the question’s comments.

First, I made a structure that contains (at least) two sounds: one for the beginning and one for the looping song. This way it’s easier to move them around together. Then I made an invisible actor, shown in the photo above. I gave it an AudioComponent and added the “OnAudioPlaybackPercent” and “OnAudioFinished” events (by right-clicking on the component and selecting Add Event).

OnAudioPlaybackPercent is more accurate, but cannot account for changes in the GlobalTimeDilation, since music doesn’t speed up or slow down like geometry does. This works by taking the length of the first song (once the AudioComponent has its sound set) and making a delay before playing the looping portion. This is like, 99.5% accurate and is noticeable if you’re studying it, but in the heat of the moment, players of your game won’t notice.

OnAudioFinished has more of a hitch, but will definitely account for GlobalTimeDilation. This event triggers when the AudioComponent… is finished playing. So just tell it to loop after that.

Choose which one of these two methods works best for your project. With either method, there will be a substantial loading hitch when first trying it out, but this is editor-only (I hope). I believe in a packaged build there will be no loading hitches.

I’m currently working on a basic plugin that comes with some basic functions and objects to work with when first starting up making a new game, including this one. Might be a while before I publish it, but just so you know.

To be honest, this solution is unsatisfactory in my eyes. Music is one of the most important parts of video games, and Unreal Engine seemingly has overlooked this. Please make a simpler, easier solution to make beautiful music for our projects!

This doesn’t seem to work anymore, there is often a “gap” and even if you try -/+ the gap you get a “crackle” sound when it plays the next song.

I can’t believe how ■■■ unreal engine is at something as basic as “Sound”

You might want to look into the TimeSynth plugin for a more up-to-date solution. Epic Games also did a live training video following their GDC 2019 presentation, which goes over these sorts of problems (timing audio with precision etc.). Here’s an older live training video from 2018 which you might also find useful. I haven’t used the plugin myself but it looks promising from what I’ve seen.

Hi Lightphobe, I did run across from this, I should check it out more.

What I ended up using was something called FMOD which has been a complete game changer, surprised Epic haven’t bought these guys like Quixel, the FMOD software makes sound, loops, smooth transitions an absolute breeze.

I have found solution to this issue. To avoid reposting, please take a look in this thread: How do you concatenate 2 sounds without delay - #30 by Dragan