Search Unity

Addressables AudioClip Works in Play Mode, Not in Build

Discussion in 'Addressables' started by cassius, Jan 15, 2022.

  1. cassius

    cassius

    Joined:
    Aug 5, 2012
    Posts:
    125
    I am using Addressables to load up Audio Clips, based on path (string) during runtime. They work without issue when in the editor's Play mode, but not during the actual build. My other Addressable assets, such as Localizations, Scenes, etc, load in a build without any issues.

    I based my code on the documentation here: https://docs.unity3d.com/Packages/c...AddressableAssets.html#loading-a-single-asset

    I'm sure I've missed something simple, like Addressables build paths or something, but they appear correct.. and as mentioned, the other assets are loading fine in the build.

    Any suggestions for things to try?

    Code (CSharp):
    1. IEnumerator PlayAudioClip(AudioFiles.AudioAndSubs audioAndSubs)
    2.     {
    3.         // Get and assign the AudioClips
    4.         AsyncOperationHandle<AudioClip> handle = Addressables.LoadAssetAsync<AudioClip>(audioAndSubs.audioClipPath);
    5.         yield return handle;
    6.         if (handle.Status == AsyncOperationStatus.Succeeded)
    7.             audioSource.clip = handle.Result;
    8.             if (GameManager.instance.DEBUG) Debug.Log("PassengerAudioActions AudioClip value is " + audioAndSubs.audioClipPath, gameObject);
    9.         else
    10.         {
    11.             Debug.LogError($"Asset for {audioAndSubs.audioClipPath} failed to load.");
    12.             if (GameManager.instance.DEBUG) Debug.LogError("Unable to get the 'handle' for the AsyncOperation for this AudioClip.  Probably need to make sure the 'cheers' filename variables are correct, or that the audio clip file for that name exists for the passenger/pedestrian", gameObject);
    13.         }
    14.        
    15.         localizedString = audioAndSubs.localizedStrings;
    16.         localizedStringEvent.StringReference = localizedString;
    17.  
    18.         if(audioType == AudioType.random) isPlaying = true;
    19.  
    20.         audioFiles.animator.enabled = true;
    21.         audioFiles.animator.gameObject.SetActive(true);
    22.         audioFiles.animator.Play(fadeInAnimation.name, 0, 0);
    23.         audioSource.Play();
    24.  
    25.         if(audioType != AudioType.thanks) passengerAnimation_Random.TriggerAnimation();
    26.         if (GameManager.instance.DEBUG) Debug.Log("PassengerAudioActions start playing", gameObject);
    27.  
    28.         yield return new WaitWhile(() => audioSource.isPlaying);
    29.         if (GameManager.instance.DEBUG) Debug.Log("PassengerAudioActions done playing", gameObject);
    30.        
    31.         // Release the AudioClip from memory
    32.         Addressables.Release(handle);
    33.  
    34. ......
    35. }
     
  2. cassius

    cassius

    Joined:
    Aug 5, 2012
    Posts:
    125
    I figured out the problem. For some reason the Addressables Group was missing the "Content Packing & Loading" and "Content Update Restriction" components. No idea how they got removed, but re-creating the group from scratch solved the issue.
     
    Syr1 likes this.