A Better Audio Manager

a new feature in my Audio Manager script!

7/18/20232 min read

The Age of Irata composer/Sound Guru ( Game Composer | Deanmanringmusic ) made a request yesterday! Dean asked "If I give you the seconds+millisecond moment in a song, can you set it to start playing again at that moment?". The goal would be to play the intro portion of a song but only loop the main portion of a track (which might be 3.5 seconds into the track). Here's how I added this feature!

Music in AoI is controlled via the Audio Management script. When you enter a new area, the "Play" method is called and this changes the music.

The first step was to attach a float "loopStartTime" variable to each soundtrack. Its default value is 0f as many songs will likely need to loop at the 0 second mark.

However, adding the "loopStartTime" float variable allows me to set a unique starting point for our loop within Unity! In this example you can see that the menuTheme sound track will play through once, and then loop at the 2.378 second mark!

Last but not least, I needed to write the logic that will actually handle the initial playback and consequent looping.

I achieved this by adding a Coroutine to my original "Play" method. This coroutine runs when we play the track, but will wait until the audio finishes its first playthrough. At that point, the start point of the track is changed, and looping functionality is turned back on!

I hope you found this as interesting as I did! It was a quick and relatively easy feature to add but took a bit of thinking so I was proud of how it all came together!.

Remember to add Age of Irata to your steam wishlist, and if you want to take part in some of our early build tests, you can sign up at the bottom of this website!

If you have any questions on how I got this working in AoI you can shoot me an email at ryley@vinciware.com, or find me one twitter! 😁

Final Thoughts