How to iterate all prefabs in project and create them in scene

Hi there, I’m very new to Unity Programming so I’m not sure what’s possible and what is not. I didn’t see this question asked before so here goes.

What I am looking to do is iterate through all the prefabs in a particular directory in my project and create/destroy them in scene so some operations can be performed.


var directory = "\assets\objects\items";

foreach(var prefab in directory)


// do something with prefab



Is this possible? Or can you only iterate objects already in a scene?

If so, how would you do it, and how do you create/destroy those prefabs?

Take a look at this following link:

This shows you how to iterate through the returned objects in a directory. After you get the returned data paths, you could simply:

Instantiate( Resources.Load( "assetDataPathHere" ) );

And destroy the cached object when you need to accordingly.

An easy solution is assigning all prefabs with a tag and just gather all gameobjects with the same tag:

var gameobjects:GameObject[] = GameObject.FindGameObjectsWithTag("PrefabTag");

And then loop through all gameobjects:

for(var gameobject:GameObject in gameobjects)
// do something with prefab