CPU spikes with Resources.Load(...)

I’m seeing CPU spikes when Resources.Load is used for AudioClips. Specifically, it is the Loading.AwakeFromLoad subroutine that has the spikes, where the Profiler is showing anywhere from 60ms to 700+ms for that process.

Corresponding to these CPU spikes I’m getting hiccups in audio playback, not necessarily from the just loaded audio. I’ve also noticed that Loading.AwakeFromLoad time will go down if I don’t use the audioclip setting DecompressOnLoad (makes sense), but then Loading.LoadFileHeaders will spike when using CompressedInMemory.

In Update, I’m calling a method LoadAndPlay(), wherein Resources.Load is called. I tried making LoadAndPlay() a Coroutine with multiple yields to spread it out over frames, but it’s definitely that one Resources.Load call itself causing the spike. Is there any approach that will allow AudioClips to load at runtime without an impact on framerate?

I’m using a lot of clips, both for sound design and music, and can’t afford to load all these assets when the scene loads. Thanks for any help!

There is now in Unity 4.5.3 a way to load resources in the background. The function is called Resources.LoadAsync() and it returns an ASynchronousOperation on which you can yield using a Coroutine! When loading large prefab objects, it can cause a spike when the load operation finishes and it has to integrate the scene, but for assets like sound files or textures that won’t be a problem.