Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    62
    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...