Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

AudioMixerSnapshot.TransitionTo doesn't work if called from Monobehavior.Start

Discussion in 'Unity 5 Pre-order Beta' started by idunlop_oefun, Nov 10, 2014.

  1. idunlop_oefun

    idunlop_oefun

    Joined:
    Aug 31, 2010
    Posts:
    225
    While testing in the editor using Unity 5.0.0b12 on Mac.

    I'm trying to implement an audio mute / toggle button to set a particular snapshot / state in Start() based on a playerPrefs. The default selected snapshot in the audio mixer is 'volume on'. refreshMixer is called as expected by the ValueChanged event.

    With hack == 0, if I run the app once and mute the audio, then re-run the app the audio will not be muted because the TransitionTo call fails (or is ignored).

    If hack == 2, it works as expected.

    I've submitted a bug report on this. I was wondering if anyone has encountered this issue and if they have a better work around?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.Audio;
    5.  
    6. public class musicManager : MonoBehaviour {
    7.  
    8.     public AudioMixerSnapshot musicOn;
    9.     public AudioMixerSnapshot musicOff;
    10.     public Toggle musicToggle;
    11.     int hack;
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.         int musicEnabled = PlayerPrefs.GetInt("MusicEnabled", 1);
    16.         if (musicEnabled == 1) {
    17.             musicToggle.isOn = true;
    18.         } else {
    19.             musicToggle.isOn = false;
    20.         }
    21.         hack = 2;
    22.     }
    23.  
    24.     void Update() {
    25.         if (hack > 0) {
    26.             hack--;
    27.             if (hack == 0) {
    28.                 refreshMixer();
    29.             }
    30.         }
    31.     }
    32.  
    33.     public void toggleChanged() {
    34.         int musicEnabled;
    35.  
    36.         if (musicToggle.isOn) {
    37.             musicEnabled = 1;
    38.         } else {
    39.             musicEnabled = 0;
    40.         }
    41.         PlayerPrefs.SetInt("MusicEnabled", musicEnabled);
    42.         PlayerPrefs.Save();
    43.         refreshMixer();
    44.     }
    45.  
    46.     void refreshMixer() {
    47.         int musicEnabled = PlayerPrefs.GetInt("MusicEnabled", 1);
    48.         if (musicEnabled == 1) {
    49.             musicOn.TransitionTo(0.2f);
    50.         } else {
    51.             musicOff.TransitionTo(0.2f);
    52.         }
    53.     }
    54. }
    55.  
     
  2. idunlop_oefun

    idunlop_oefun

    Joined:
    Aug 31, 2010
    Posts:
    225
    Additionally when targeting iOS, the Xcode build fails:

    Code (CSharp):
    1. Undefined symbols for architecture armv7:
    2.   "RegisterClass_AudioMixerController()", referenced from:
    3.       RegisterAllClasses() in RegisterMonoModules.o
    4.   "RegisterClass_AudioMixerGroupController()", referenced from:
    5.       RegisterAllClasses() in RegisterMonoModules.o
    6.   "RegisterClass_AudioMixerSnapshotController()", referenced from:
    7.       RegisterAllClasses() in RegisterMonoModules.o
    8. ld: symbol(s) not found for architecture armv7
    9.  
     
  3. biscito

    biscito

    Joined:
    Apr 3, 2013
    Posts:
    125
    same =
    Code (CSharp):
    1. Undefined symbols for architecture armv7:
    2.   "_OBJC_CLASS_$_ASIdentifierManager", referenced from:
    3.       objc-class-ref in DeviceInfo(DeviceInfo.o)
    4.   "RegisterClass_AudioMixerController()", referenced from:
    5.       RegisterAllClasses() in RegisterMonoModules.o
    6.   "UnityPause(bool)", referenced from:
    7.       -[UnityAdsUnityWrapper unityAdsDidShow] in UnityAdsUnityWrapper.o
    8.       -[UnityAdsUnityWrapper unityAdsDidHide] in UnityAdsUnityWrapper.o
    9.   "RegisterClass_AudioMixerGroupController()", referenced from:
    10.       RegisterAllClasses() in RegisterMonoModules.o
    11.   "RegisterClass_AudioMixerSnapshotController()", referenced from:
    12.       RegisterAllClasses() in RegisterMonoModules.o
    13. ld: symbol(s) not found for architecture armv7
    14. clang: error: linker command failed with exit code 1 (use -v to see invocation
     
unityunity