Looping music playlist playing through levels

I’ve been looking through tutorials and tips for several hours but none of the solutions cover everything I need.

I want the music to play sequentially throughout the game, and to be able to switch to other songs and exclude selected ones. As if the player was running a playlist in Winamp in the background.

So, to have an impact on the playlist at every moment of the game, e.g. to scroll to the next song, I try to put the entire logic in GameInstance.

First I wanted to use Sound Cue with Concatenator, without Loop Node in it it worked, but with Loop Node it stopped working when I was loading a new level. For some reason, only when we create a reference (here SET Audiocompref) then it works without a problem;

However, I don’t know how to add the logic I care about here, how to change songs from the menu in the game?

Later I tried to create a playlist with songs and run them via scripts. This makes it easier to add logic and maneuver more easily. The problem is big, however, and there are two problems.

One is to determine when to change the track to the next one, Dispacher OnAudioFinised for some reason just doesn’t work, after finishing the track it doesn’t start. Is it because it’s GameInstance?;

So instead I used SetTimerByEvent and set the length of the current song as its time;

This works, but when we minimize the game, the music stops and the event timer continues, causing the next song to start too early.
Moreover, when we stop the game using the SetGamePaused node, our event also stops, causing when the song ends the next track to start with a delay.
I don’t see a TickOnPaused option anywhere in GameInstance.

Please help.

So, I’ve come to a solution. This eliminates all problems and guarantees that all functions (I hope) can be implemented.;

A little explanation.
In the Blueprint of the first loading level in the game, in its EventBeginPlay, use Cast To Game Instance and run a Custom Event in it.
That Custom Event triggers nodes in the above screenshot.

The whole thing starts with the IsPlaying query because in my game we go back to this first level and it prevents the music from restarting.

Next we have SpawnSound2D which simply launches the given song.
For its Sound Input, we take a given position from a variable of type Sound Base - Array, where we store all our songs.
The Index of this Array is selected by an Integer variable by default set to 0, that is, the first position of the Array.

Next, after SpawnSound2D, we save a reference from its Audio Component, which will be used to check if the music is currently playing, as in the beginning of this screenshot.

Then we set SetTimerByEvent with Time set to any number large enough not to burden the performance, This Event checks every second in my case if the music is playing. If it turns out that it doesn’t play, it means that the song currently playing is over, so we add 1 to a variable in my case called SongNumber, then we check if SongNumber is greater than or equal to the number of all songs in the Array.
If it is smaller, the script returns to SpawnSound2D again which starts the next track, the next one because we increased by one the SongNumber which indicates which Array index to choose.
If SongNumber is greater than or equal to the length of the Array, it means that we are on the last song in the list of songs, so we reset SongNumber to 0 so that when we return to SpawnSound2D, the script will run the first song in the list, thus looping the whole thing.
We check “greater than or equal to” and not just “greater than” because the values of the Array variable start at 0, that is 0->1->2… and the LENGHT node that gives us the number of values of the Array variable counts from 1. That is in case Array has values - 0,1,2, LENGHT of this Array will be 3.
So when the SongNumber is equal to the LENGHT of our Array, it means that we already have too much number and we have to loop the whole thing now.


If you have a more elegant solution, or a more correct one, I still ask for it.

So what I’m assuming your asking is “how can I seamlessly play songs from one level to another and know when they end?”

This, in the game instance, worked flawlessly for me:



Not sure how it’s working for you without using the play node though- it won’t for me.
In order for the On Audio Finished to work through transitions, you do need to keep the audio as a variable. I assume audio and the object exist separately or something- like the audio will do it’s own thing, and the object is just how we control it- not sure.

Also, just a blueprinting tip- try to spread out more. You have infinite space, there’s no need to stuff everything together. If you want a clean look on the outside, you can also select a bunch of nodes and select collapse nodes:

Funny, I set everything exactly like you did and still OnFinish won’t start.

As for the Play node;
CreateSound2D only creates the AudioComponent, which later needs to be launched via Play, while SpawnSound2D creates the AudioComponent as already launched.

Ah- so I used the wrong node.
Maybe try your logic in a new project like I did. This is almost certainly the cleanest it could get, so you might want to try.

I’m really not sure what’s wrong. SpawnSound2D works, CreateSound2D works, it works in a function, it works in an event, it works with sound cues as well as non-cues, it works when directly connected to itself, and the delegate calls through both create event and being directly wired. I can only think that something else in your project is interfering.

I made working music player with a playlist, I share the project here UE4 Music Player with Playlist - YouTube