Search Unity

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

AudioClip.LoadAudioData returns true but clip remains unloaded

Discussion in 'Audio & Video' started by fredrik-larsson, Feb 6, 2017.

  1. fredrik-larsson


    Nov 3, 2015
    In our project we are having issues with certain AudioClips not being loaded when they should be (I.E when we want to use them).
    My first suspect was the "Preload Audio Data" setting on the audio files not working properly as the problem only seemed to occur after we loaded the same scene a second time.
    Therefore, I turned that setting off and added my own "Preloading" by calling LoadAudioData manually in objects Start() function. This caused the same symptoms with the exception that it now occured 100% of the time instead of working properly only the first time. The funny thing I noticed though was that LoadAudioData returned true although the LoadState was still set to "Unloaded". This only happens for some specific objects though (our main characters) and there are other objects that reference and use the same audio resources.

    Has anyone got an idea at what could cause this behaviour?

    What could cause AudioClip.LoadAudioData to return true but still leave the LoadState at "Unloaded"?

    Unity Version: 5.4.2f2
    Relevant audio clip data:
    - Load in Background = false
    - Load Type = Compressed in memory
    - Preload Audio Data = false (in my test, true otherwise)
    - Compression format: Vorbis
  2. Daniel-Bengtsson


    Feb 8, 2017
    (Before anyone gets confused; I'm actually OP, Fredrik is just a colleague who posted for me because my account was broken).

    OK, so I've done some more research and what seems to be happening is:
    1. Game enters loading screen and our objects using the audio clips are loaded.
    Here, all AudioClip instances using the same resource seem to be getting the same InstanceID (This sounds correct!)

    2. Game nears the end of the loading screen and some more objects using the same audio clips are created.
    Here, the AudioClips which should be getting the same InstanceIDs as the ones created in step 1 suddenly gets a new InstanceID, indicating that they do not share their data with the previously created AudioClips.
    Unity seems to be creating multiple objects with separate instanceIDs for the same audio clip (my assumption here is that this should never happen, please correct me if I'm wrong). However, all AudioClips are usable and their data is loaded.

    3. Game starts the first frame of the ingame loop
    Unity (or fmod?) unloads the audio data for the last created instances of the duplicate AudioClip objects. After this has happened, all AudioClips that Unity attempts to preload will remain unloaded and if I attempt to manually load them using LoadAudioData() I get the behaviour described in the post above.

    4. The game reaches a point where one of the unloaded AudioClips should be played
    As the AudioClips loadstate is set to "Unloaded", Unity attempts to load the audio when Play() is called. This results in the following error message: "Error: Cannot create FMOD::Sound instance for resource archive:/CAB-a9ad22f9a6a566594de2d4f439eb830c/CAB-a9ad22f9a6a566594de2d4f439eb830c.resource, (File not found. )"

    Note that audioclips loaded using WWW are not affected by this and can be loaded and played just fine.

    I'm leaning towards something evil happening between step 1 and step 2 but I can't figure out what it could be...
  3. Korindian


    Jun 25, 2013
    I'm having a similar problem with the same error. Loading an AssetBundle with AudioClips into a dictionary, and then unloading the AssetBundle passing false. When I try to access those clips, I get the same "Error: Cannot create FMOD::Sound instance for resource archive", even though a Debug.Log before trying to play the clips show that they all exist.

    There was a bug for this in the issue tracker that says fixed, but apparently it's not. Can someone from Unity look at this?
  4. rogueNoodle


    May 11, 2013
    @Daniel-Bengtsson - I'm wondering if you were ever able to work around this problem? I seem to facing a similar issue where AudioClips that were initially loaded and then unloaded can not be reloaded again, even though AudioClip.LoadAudioData returns true.