Playing audio after one completes ?

Hey Guys, I am currently working on a project which requires me to add audio (Background Music) to the game. I would like to know what I should do so that after a random audio cue is played, another random cue will be played from the track.

I want to make it like background music playing one after another.


You can bind a function to “OnAudioFinished” on the AudioComponent created when you use CreatesSound2D. In that function you can play the next song.

3 Likes

You can also just create one sound cue, add a “random” node to it and add all your music tracks to that one. Looping this cue will then play random music for ever without the need of any extra programming. Just play it once and forget about it :grin:

A third approach, needed if you choose to move forward with a MetaSoundSource, would be to use an MS random node to generate a number to select out of a WaveAsset array. The WaveAsset array would contain all your waves. The number would be used in a Get and fed into the Wave Player node (specifically the Wave Asset input). The OnNearlyFinished output of the WavePlayer, would set a Trigger variable. You would pull off a Delayed version of that variable to trigger the WavePlayer->Play, the Random number generation trigger, and the Get Array node.

To start it initially, you would have hook the OnPlay input to all of those same nodes the delayed variable trigger is connected to. This would involve using a Trigger Any node.

Using this approach, all the logic goes in the MetaSoundSource with the BP only starting the MetaSound. This can be set up to run across levels and loading screens too.

Edit: I remembered that there is an example that @lantz.anna_1 posted in this thread. It is a screen shot showing the use of exactly what you are looking for and is about 5 posts from the bottom: