Loading audio dynamically iOs

Hello
I’m working on a music game for iOs where you have about 20 instruments available to drag into the scene. The audio for each instrument only plays when it is dragged into the scene, and only a maximum of 6-7 can be in the scene at one time. I am finding it to be a huge memory hog to have all 20 audio clips loaded into memory at once. What is the best way to play load the clips into memory only when I need them, and unload audio clips when they are removed from the scene?

Currently, I have a script for each instrument with an audio clip that I assign in the inspector. Each instrument has its own audio source and I simply call audio.Play() and audio.Stop() when the instrument is dragged into/out of the scene. There’s got to be a better way!
Thanks for your help.

You could try:

  • Putting the audio clips in a Resources folder
  • Loading just the ones you need (using the name of the clip)
  • Using Resources.UnloadUnusedAssets (which you can yield in a coroutine) to unload unused ones
  • Specify that you want to stream the clips from “disk” rather than load them all into memory by fiddling with the import settings on the clip