Audio Source Mixer Group Issue

Updated on October 30, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on October 29, 2018

Brackeys has a video on using the Mixer https://www.youtube.com/watch?v=6OT43pvUyfY

My problem is I set different groups in the inspector but they are not getting set when created

AudioManager.cs

 

void Awake()
 {
 if (instance != null)
 {
 Destroy(gameObject);
 }
 else
 {
 instance = this;
 DontDestroyOnLoad(gameObject);
 }
 
foreach (Sound s in sounds)
 {
 s.source = gameObject.AddComponent<AudioSource>();
 s.source.clip = s.clip;
 s.source.loop = s.loop;
 
s.source.outputAudioMixerGroup = mixerGroup;
 }
 }

 

Sound.cs

 

using UnityEngine.Audio;
using UnityEngine;
[System.Serializable]
public class Sound {
public string name;
public AudioClip clip;
[Range(0f, 1f)]
 public float volume = .75f;
 [Range(0f, 1f)]
 public float volumeVariance = .1f;
[Range(.1f, 3f)]
 public float pitch = 1f;
 [Range(0f, 1f)]
 public float pitchVariance = .1f;
public bool loop = false;
public AudioMixerGroup mixerGroup;
[HideInInspector]
 public AudioSource source;
}

 

  • Liked by
Reply
1 on October 29, 2018
on October 29, 2018

I set the group ‘sound’, but the group music is used

 

Here is the code I used
http://old.brackeys.com/wp-content/FilesForDownload/AudioManager.zip

Show more replies
  • Liked by
Reply
Cancel
0 on October 29, 2018

Does anyone have any insight on this?

  • Liked by
Reply
Cancel
1 on October 29, 2018

is your arraylist containing the Sounds (called sounds) empty?

on October 30, 2018

No, you can see in the attached image that I have three sounds in the array [crash,purchase,theme] 

 

I have two mixer groups [music, sound]

 

crash is set in the sounds array to have a mixer group of type sound

 

But when I run the script and the Audio Source is created for crash it has the mixer group of type music set and not sound

Show more replies
  • Liked by
Reply
Cancel