Fill an array with prefabs?


I am trying to spawn random rocks at random spawn locations. I made the rocks into prefabs and tagged them as “Rocks”. On start the Spawn Location array fills up. The RocksToSpawnClones array and the RocksToSpawnPrefabs array remain empty and no rock prefabs are spawned.

You are using GameObject.FindGameObjectsWithTag("Rock");

That method will only find objects in the active scene that is playing. However, you are saying that you have prefabs, which are physical files in your harddrive. This method won’t find them (imagine looking for every directory and file, checking if it is a prefab and tagged as rocks).

What you need to do is to fill the rocksToSpawnPrefabs list manually in the editor screen. Surely, you have a game object with this script attached. See script field in the inspector, then drag and drop your prefabs to RocksToSpawnPrefabs list.

See this video for how it is done: Lock Inspector to Populate Array - Unity3d - Hot Tip - YouTube
Mind that, you need to drag your prefabs from your folder view to do that.