Hi,
Really new to Unity.
Been playing with it for a little while and audio seems complicated
Searched the Asset Store for an “audio manager” and found below free one:
https://assetstore.unity.com/packages/tools/audio/sound-manager-audio-sound-and-music-manager-for-unity-56087
Above audio manager seems ok, but the author suggests to set up a script with music/effects loaded as prefabs?
How would we create a new script with all music & effects loaded as prefabs?
Let us know, thanks!
Jesse
You could use prefabs but probably a better approach is to use a ScriptableObject-based system to define additional information about your sounds, to group them by name or function, etc.
The simple approach I’ve used is an “AudioThing” that derives from ScriptableObject and has properties that my audio engineers can twiddle:
- which audio clip (or clips) it points to
- volume
- category (voice, music, sfx, etc.)
- priority
- chain-on sound
- any event callbacks to send (usually just a simple string sent to a function)
- any other things like shuffling among different sounds, pitch changes, etc.
Then I just have a simple function that accepts one of those AudioThing objects and knows how to play it. This approach exposes all the above settings to my audio engineers so they can fiddle with it endlessly without any effort from the engineering side.
Thanks for the reply.
Is there an example of your suggestion somewhere on the Internet.
Unity audio has been difficult to get into.
Jesse
Well the easiest start is to just make an audio thingy with a single setting, such as volume, something like (and I’m just typing this, not using a compiler):
using UnityEngine;
[CreateAssetMenu]
public class AudioThingy : ScriptableObject
{
public AudioClip Clip;
public float Volume = 1.0f;
}
As long as the above is put into a file called AudioThingy.cs, you should be able to right-click and create one of these assets for each “audio thingy” you want, then name them appropriately, drag them into inspector fields, etc., and populate them with Audioclips.
Now write a method that sits on a GameObject with an AudioSource on it, and call that method to say “play this AudioThingy” and make it copy the volume setting out and apply it before playing.
Now everything beyond this is just features to make it more useful. Start simple, get it going, commit it to source control (you ARE using source control, right?) and keep building on it as you need each feature.
Tried your code, has error:
“Can’t add script behavior AudioThingy. The script needs to derive from MonoBehaviour!”
Changing the line to:
“public class AudioThingy : MonoBehaviour” seems to work.
I was looking for a method to load all music and sound effects one time at beginning to be used in different scenes.
Will this work for the above?
Thanks!
Jesse
That would be how you would make a prefab.
The above script does NOT get added to a GameObject the way a Monobehavior does, because it is something else, a ScriptableObject.
With my original script (and I just verified it works properly), you create a template to make AudioThingys, which are ScriptableObject assets, i.e., files on your disk.
So instead of dragging it onto a GameObject, right-click on your project window and say Create → Audio Thingy and you will make one. Generally make one per audio thingy you want.
Hi,
OK, seems to be working now as you described.
How would we play the AudioThingy sound from another script?
Music should loop and persist between scene changes.
Sound effects should play once.
Let us know, audio on Unity is pretty complicated…
Jese

The AudioThiny listed above is the barest start of an asset management tool, one that lets you preset a volume with a particular clip and then associate it with a specific audio event in your code. If you want a full-function audio manager, you need to either write it or buy one. I’d just write it.
You can use the static function AudioSource.PlayOneShot() to make it cheap and cheerful, but all the other functions you list above (persist music, loop music, etc.), you need to actually write that, probably using some kind of Singleton structure so that it persists across scenes.
Ultimately it’s only gonna be a few lines of code here and there so just get started with the simplest play sound effect and build from there. You’re NOT gonna write it in one day, but you certainly can write the first play-sound-effect in about two minutes, so get started! Just like everything else in Unity, you would use a reference to an AudioThingy as your main point of talking about a particular sound across the scope of your game, at least that’s what I would do.
One last question hopefully…
I wish to use this free Unity Sound Manager:
The sound manager works with AudioSources and your “AudioThingy” uses AudioClips.
How can we convert AudioClips to AudioSources to be used with above sound manager?
Code is below.
Let us know, thank you…
Jesse
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using DigitalRuby.SoundManagerNamespace;
public class ScreenFade : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Vector3 position = new Vector3(0, 0, 0);
transform.position = position;
DigitalRuby.SoundManagerNamespace.SoundManager.PlayLoopingMusic("TitleBGM");
// ERROR: error CS1503: Argument 1: cannot convert from 'string' to 'UnityEngine.AudioSource'
}
}
You cannot “convert” one into the other.
Let me give you an analogy: If an AudioSource is a gun, an AudioClip is a bullet.
You don’t convert a bullet into a gun. You put a bullet into a gun, then you fire the gun. You don’t fire the bullet, the gun does that for you when you pull the trigger.
An instance of an AudioSource has a field to set the AudioClip you want that AudioSource to play.
There are also static helper functions in AudioSource to play non-instanced sounds, but they don’t give you fine control over lifetime.
Please review the script reference docs for AudioSource and AudioClip. You really should just work through some Unity audio tutorials because you need to have a firm foundation on what is what.
Hi,
I think I have something below that should work but does not.
It compiled with no errors, but the “Title-BGM” does not play when the game is running?
What am I doing wrong?
Thanks!
NOTE: I do get the below warning message, don’t know why:
Assets\Scenes\ScreenFade.cs(11,17): warning CS0649: Field ‘ScreenFade.audioSrc’ is never assigned to, and will always have its default value null
Jesse
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using DigitalRuby.SoundManagerNamespace;
public class ScreenFade : MonoBehaviour
{
public AudioClip audioClip = null;
public AudioSource audioSrc = null;
// Start is called before the first frame update
void Start()
{
Vector3 position = new Vector3(0, 0, 0);
transform.position = position;
audioClip = Resources.Load<AudioClip>("Scenes/Title-BGM");
audioSrc.clip = audioClip;
audioSrc.volume = 1.0f;
SoundManager.PlayLoopingMusic(audioSrc);
}
