I have successfully imported a bunch of .fbx models into my Unity hierarchy and I was wondering if there's any easy to write a script (which will ultimately be attached to an empty game object) that will automatically instantiate the models at coordinates 0, 0, 0.
They are not in the Resources folder (since I've read from the Unity documentation that it is inefficient) so I can't use Resources.Load(...). If this is the only way, then I guess I can use it but I was just wondering if there's any other way.
Thanks for any help in advance.
By "hierarchy" do you mean the project view? If you've already dragged the models into the hierarchy then you don't need to do anything else. Is this something you want to do at runtime or in the editor? The question is pretty unclear. Anyway, not sure if this is what you mean, but you can make prefabs out of the models, and use Instantiate.
var models : GameObject[];
function Start() {
for (model in models) {
Instantiate (model, Vector3.zero, Quaternion.identity);
}
}
Actually you have to understand how Unity works. Unity only include those assets into the build that are used somewhere (referenced by a script variable or any other component). The final decision what will be included depends on what levels you include. The levels contains some of your predefined objects that may refer to other prefabs so they are included in that level.
Assets that aren't referenced somewhere will not be included in the build. If you want do use an asset without the need of manually setup the reference in the inspector you have to put those assets into the `Ressources` folder. Now you can use `Ressources.Load` to get the prefab reference dynamically at runtime. The downside is that everything that is inside the Ressources folder is included and for streamed webbuilds all those assets get loaded with the first level.
Just a sidenote: imported models (.fbx) are also prefabs but a special kind. These prefabs can't changed inside Unity. You can only reimport them (which should happen automatically when you change the fbx file). The type of a prefab is given by the PrefabType and can't be changed.