Hi All,
I want to instantiate prefabs in my c# scripts, but i dont seem to be able to call them up from the regular asset tree.
All the examples Ive found have them in the resources folder.
This really ruins the way im organising my data storage.
Is there a way to load from a standard asset folder? Would it be much slower? (dunno if unity is caching stuff in resources). If i put my whole structure inside Resources is that ok and can i use paths within resources to acces stuff that way too?
thanks in advance 
Ok Ive found out that indeed unity caches the resources folder as guaranteed usage items (as opposed to stuff outside which it only adds to builds if attached to active gameobjects).
However, I need to generate things dynamically.
For instance a script may spawn 1 of 5 different prefabs, or spawn a single prefab and assign 1 of 5 materials to it.
I cant see how youd do this in the normal unity exposed interface without haveing slots for each prefab type and then a switch statement about which to spawn. This coudl end up with a lot of draggin and dropping and some seriously oversized exposed variable lists.
Wierdly it seems fine to attach existing scripts/textures etc that are not in the resources folder, its only prefabs that seem to be effected (maybe coz they are already gameobjects+components)
Again I guess you could just create a blank gameobject and attach a script that adds all the components (a prefab on the fly so to speak)
but this would leave even less to the IDE. hmmm i think the amount of stuff i generate procedurally has got me into this quandry…
Scripts are all compiled no matter what. This is behaviour of the Mono Compiler, and only on iPhone can anything be stripped out afterwards.
As for creating prefabs dynamically create a spawner script that has an array of Transforms, then you can have a variablly sized list of prefabs, and instead of using a switch, you can use
public Transform[ ] prefabs;
at the top to place the prefabs, and
Instantiate(prefabs[Random.Range(0, prefabs.Length - 1)]);
It will spawn any of your random prefabs, and you can collapse the array so it’s not 2-3 pages of oddly named hard coded length random variables.
Then you can edit your Prefabs individually in the Editor and have your spawner create them on the fly when actually playing the game.
Now that is neat!
Thanks Ntero, really helps me keep things organised too!