Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Can I create or load an AudioMixer via script?

Discussion in 'Audio & Video' started by JonBPS, Mar 23, 2015.

  1. JonBPS

    JonBPS

    Joined:
    Dec 16, 2013
    Posts:
    10
    I have created an audio mixer asset by following the video tutorials.

    Instead of assigning the mixer through public values I want to know if I could load the audio mixer as a resource at run time? or alternatively create one.

    I tried 'Instantiate(Resources.Load("MasterMixer")) as AudioMixer;'.
    But I get an error 'snapshot.IsValid () && (snapshot->GetAudioMixer () == PPtr<AudioMixer>(this))'.
     
  2. summerian

    summerian

    Joined:
    Jul 6, 2014
    Posts:
    140
    I'm interested in knowing this too.

    Basically I'd like to a level scene to check if it was loaded into the main scene. If yes, then route audio through main mixer, if not then create one on the fly for testing purposes.
     
  3. aihodge

    aihodge

    Joined:
    Nov 23, 2014
    Posts:
    163
    I'm also interested in finding out if this is possible.
     
  4. itthereforeim

    itthereforeim

    Joined:
    Apr 28, 2014
    Posts:
    24
    in MonoBehaviour

    AudioMixer mixer = GetComponent<AudioSource>().outputAudioMixerGroup.audioMixer;

    is this work for you?
     
  5. TimSchroeder

    TimSchroeder

    Joined:
    Aug 27, 2014
    Posts:
    9
    malkere likes this.
  6. webik150

    webik150

    Joined:
    Mar 23, 2013
    Posts:
    65
    I would love this too (I need to find the AudioMixer for saving and loading sound config). For now, I will probably have to go with Tim's method...