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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Resources.Load () and Audio Load Type

Discussion in 'Editor & General Support' started by renman3000, Sep 28, 2012.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,681
    If I am using Resources.Load to load in audio files as needed, does setting the audio file's Load Type ( stream from disk, compressed in memory....) make any difference to memory and performance?
     
  2. Ville

    Ville

    Joined:
    Oct 5, 2012
    Posts:
    19
    I'd like to know that too. In my testing it seemed like it made no difference, the entire audio clip was decompressed into memory no matter what I set the Load Type to. Anyone got it working?
     
  3. wickedworx

    wickedworx

    Joined:
    Mar 13, 2013
    Posts:
    54
    It doesn't, unfortunately. If you use Resources.Load directly on an audio clip - it will always load fully in to memory. I found another thread on this the other day, but can't find it now.

    One workaround is to create a prefab which just contains a script which references your audio clip. Do a Resources.Load on this new prefab instead, and the referenced audio clip will be loaded respecting the Load Type (e.g. stream from disk) setting.

    I'll be adding this functionality (in a cool automated, fuss-free fashion) in to my audio toolkit very shortly!
     
  4. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    Works great!

    Thanks for sharing...
     
  5. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    150
    Well, after some additional testing, I've found out that the level loads much slower when f.e. loading a prefab with 5 music audioclips attached.
    So it seems that either all the music is loaded in advance, or there is some preloading going on that slows down the level load
     
  6. NoBullIntentions_P

    NoBullIntentions_P

    Joined:
    Jul 2, 2012
    Posts:
    311
    Thanks for the suggestion, WickedWorx. Although a little inconvenient, this does sound like a good workaround for the audio bugs/missing features. I've tried it out and the results are good, but how can I confirm that the audio is actually being streamed and not loaded in full? It sounds as though you've satisfied yourself that it is, in fact, respecting the streaming setting, but I'm not actually sure how I can demonstrate that it's doing that for me too. You seem to be a bit of an audio expert, so I'm sure you're right but I'd like to make sure I haven't done anything different to you or that I'm not getting different results.

    EDIT: For instance, I'm looking at the profiler, and I see the same audio memory usage before and after playing the streaming sound. Which suggests that it's actually loading in full before you set it playing. So it's not streaming at all. Perhaps this is the wrong metric to use, or perhaps I'm doing something wrong?
     
    Last edited: Dec 15, 2013
  7. ponx

    ponx

    Joined:
    Sep 13, 2010
    Posts:
    42
    thanks a ton for sharing, wickedworx!