Why are Audio Clips in my game objects loading so slowly? Not resource files.

Hi, I’m seeing a HUGE spike of 0.5 - 1 second when I play the second AudioClip that has been dragged into my Gameobject, which is in the Scene from the very beginning. This is not a “resource file audio clip”, and as I understand it, it should not need to “load” because the Audio Memory it uses is already taken up once the scene starts, because the audio clip is “in the scene” per se.

Profiler says “Loading.AwakeFromLoad” is taking all the time. Screen shot of profiler attached. Any idea how to stop this from happening? The clips are all marked as streaming if that matters?

Hi jerotas,

Could you be more precise?
Which format is the file in?
What do you mean by ‘second AudioClip dragged into my gameObject’ ?
Are other sounds already streaming?
Which platform?

And, did you know that AudioClips, even when set to streaming, may be fully loaded in memory when running in the editor?

Cheers,

Gregzo

It’s a wav file, and it’s a public variable of type Audio Clip. Another sound was already streaming, then I assigned the 2nd audio clip to the audio component of the same game object and told it to play. Then the performance spike happens.

By the way, turning off streaming fixes the problem.

Try it in a build, seeing the same spike?

My guess is that Unity pre-loads your entire clip ( the first one ), but not the second, which it might do once you assign it / call play on it’s AudioSource. I may be wrong, but if I were you, I’d make a quick standalone build first.

Took me a while to figure out why AudioClip.SetData was working in the editor where it shouldn’t, 'till I saw the obscure truth: your load settings are honoured in builds, not in the editor…

1 Like

It was reported that the spike happens in the build as well. Anyway, thank you.

The last Unity release has this in its bugfix patch notes:

  • Audio : Fixed regression with AudioClips that are flagged as streaming

Could this be relevant?

It could be, thanks for the info. Might want to try with the very latest Unity (and streaming on).