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

How do I get to the AudioMixerSnapshots of a cloned AudioMixer?

Discussion in 'Audio & Video' started by RoelfMik, Apr 15, 2015.

  1. RoelfMik

    RoelfMik

    Joined:
    Apr 7, 2013
    Posts:
    5
    When I apply AudioMixer.FindSnapshot() to a cloned AudioMixer, it wil return the Snapshots of the original AudioMixer rather than the cloned one.

    I want to interpolate the Snapshots of the cloned AudioMixer using AudioMixer.TransitionToSnapshots(), but I can't get a reference to the cloned AudioMixer's Snapshots.

    Does anybody have any ideas as to how to solve this? Any help is very, very much appreciated! Here's a simple test project illustrating the problem: https://drive.google.com/file/d/0B4PGrnbx86xCR3hkM1FSc29wQ3c/view?usp=sharing

    Here's some code:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Audio;
    3. using System.Collections;
    4.  
    5. public class Cloning_Problem : MonoBehaviour
    6. {
    7.  
    8.     public AudioMixer _AudioMixer;
    9.     public AudioMixer _AudioMixer_Clone;
    10.  
    11.     public AudioMixerSnapshot[] _Snapshot;
    12.     public float[] _Weight;
    13.  
    14.     void Start()
    15.     {
    16.  
    17.         _AudioMixer_Clone = Instantiate(_AudioMixer);
    18.  
    19.         _Snapshot = new AudioMixerSnapshot[3];
    20.  
    21.         //This returns the Snapshots of _AudioMixer, instead of _AudioMixer_Clone...
    22.         _Snapshot[0] = _AudioMixer_Clone.FindSnapshot("A");
    23.         _Snapshot[1] = _AudioMixer_Clone.FindSnapshot("B");
    24.         _Snapshot[2] = _AudioMixer_Clone.FindSnapshot("C");
    25.  
    26.         _Weight = new float[3];
    27.  
    28.         _Weight[0] = 0.2f;
    29.         _Weight[1] = 0.4f;
    30.         _Weight[2] = 0.4f;
    31.  
    32.         //Which results in this method failing, because it cant find the Snapshots on the cloned AudioMixer...
    33.         _AudioMixer_Clone.TransitionToSnapshots(_Snapshot, _Weight, 0.1f);
    34.  
    35.     }
    36.  
    37. }
    38.