I Only got a Single-ton Thing Done Today!

It’s day 46 of my metamorphosis into a Software Engineer! And though sometimes I feel like a chubby caterpillar still munching away with grandeur dreams of being the butter of the skies, sometimes I get a glimpse of the lush landscapes of software development and future prospects only to realize, that its real.

One such moment came today, as I mulled over the challenge of being able to create a system to funnel all of our game sounds through. While all games, programs, apps, nearly everything developed today has some sort of music, sound, sound effects, or sound feedback involved, so one would think that getting sound to work would be a simple process, no?

Well, like most things I write about in my development blog, yes, and no. But that’s okay, because development is just that, development — growth. Unity has some powerful tools at its disposal to utilize in order to play sounds, a few of the like of:

  • The Audio Mixer (think audio controller, the knobs on a radio or boom box — oh jeeze).
  • Audio Source (the speaker).
  • Audio Clips (the CDs for those of us who remember what that is, or cassette tape for those of us who want to date ourselves, or a-tracks for those of us who are dust).

Those are some of the primarily used components and the basics of audio via unity. The challenge comes when trying to make a manager that utilizes these components — a single manager for ALL the sounds in the game. I mean, you could use multiples of these items, but then it gets kind of messy and inefficient as your components for SOUND will be everywhere. The solution? A mixture of techniques that I learned from the internet, Austin Mackrell (one of the GameDevHQ intern Leads), and Al Heck (GameDev HQ art asset specialist). This came in the form of using:

  • A Singleton Pattern Design script for the Audio Manager
  • A master audio mixer, divided into groups to handle the different types of sounds.
  • A Do not Destroy Script that I found via Google.

Now, you’re probably thinking, how the heck do these things come together?

The answer? GLORIOUSLY!

The odds are ever in my favor.
Part 1

A singleton design audio manager, complete with instructions on how it all works. It’s actually a very simple concept, its a script in which all scripts can use to have a singular script handle functions publicly. As long as its only one script doing this. A single-ton script. *ba dum chee*

Part 2

This audio mixer has all the sounds in the game to be fed through it.. The groups on the left handle the volume levels for the individual groups that I set. In this case, background music, and sound effects. They are both children components of the master mixer therefore if the master mixer is turned down, in turn the child group mixers will also be turned down (or up).

Part 3

Lastly, we have our Audio Manager with the Singleton Script and a Don’t Destroy script that I found on the Google. It’s actually really interesting and makes it so the object it’s on is not destroyed when changing or loading scenes. I also included some logic to destroy itself a copy of it is generated upon the loading of the original scene in which it comes from. This is so that we do not accidentally have 20 of these game objects each playing music if we restart the game 20 times.

Using these three items to create the audio system will have such a level of control because now we can control what clip, and the volume through the singleton design. Further globally control the volume through the Audio mixer, and lastly, have consistent background music playing, and not being interrupted by scene changes thanks to the Don’t Destroy script.

I could go into more detail on this, but I think I may need to do a little more tinkering and experimenting with this design before I can confidently recommend or provide a tutorial on how this all really works.

I’m beat, so I’m going to sign off here, have a great and wonderful day!

— Ryan

Its a wonder why I’m still single-ton, right?

Ambitious Software Engineer at GameDevHQ.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Migrating a NPS (Radius) server role from Windows Server 2012 R2 to 2019

Apache DolphinScheduler 2.0.1

(Rails_22) google map

5 Signs You Should Move Your Business to the Cloud

What Is the Cost of Integrating a Payment Gateway to a Website or Mobile App

How was your day? 24hr review feature

My Journey at LetsGrowMore(LGM-SOC)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Yamura

Ryan Yamura

Ambitious Software Engineer at GameDevHQ.

More from Medium

How to Approach an Object-Oriented Design Problem

From a software interviewer’s eyes…

No Code & Low Code Web Design

How do you do REST integration | Step-by-Step Methodology