Search Unity

static audioclip array

Discussion in 'Scripting' started by loopyllama, Apr 7, 2012.

  1. loopyllama

    loopyllama

    Joined:
    Apr 6, 2009
    Posts:
    71
    Hello,
    I have a prefab that gets placed 30 times. I have an array of sounds on this prefab. Previously this was a public array of AudioClip and I assigned 4 sounds to this prefab in the inspector. I realize that each of the 30 prefab instances had its own AudioClip array of the same 4 sounds, so later I changed the code to have a public static array of AudioClip. Since public static is not serialized I assigned the 4 clips in code, making sure to only load them once. This made more sense to me since the 4 sounds in the array will be the same for each prefab. I thought it better to have 1 static copy for all the prefabs than to have 30 arrays, 1 for each instance.

    It is pretty convenient to assign things in the inspector so I am wondering: If I had 1,000 objects, how would having a public array (a copy for each prefab) stack up against a public static array. Could the public static array be that much better when dealing with AudioClips? I am hoping someone can chime in with the answer to avoid creating a benchmark test. I would think the only penalty would be the arrays themsleves. But wouldn't they simply contain references to the audio clip on disk, making it not so bad?
     
  2. woodygoody

    woodygoody

    Joined:
    Aug 23, 2011
    Posts:
    164
    Almost my problem:
    If I have an array contains four elements, How can make this array ALWAYS contains the four elements without change during my game ?