- Home /
Place assets onto scene
I just started using Unity and read/watched a lot of tutorials. My basic (probably elementary but I couldn't find a solution after some searching) problem is that I have a bunch of models (.FBX files) and I have them imported in Unity. I could drag and drop them onto the scene and they work fine. But I am trying to write a script (which I attached to an empty gameobject to run it) that reads the names of these assets from a text file and tries to load and place them onto the scene at run time. The problem is not with reading or getting the names from the text file, they work fine.
The FBX files are inside a Resources folder so that I can use Resources.Load(nameOfTheObjectAsString). After much tinkering it is complaining that there is no Renderer attached. Do I have to somehow load the FBX file as a GameObject for it to have a Renderer attached to it? Can Resources.Load() return the asset as a GameObject? My understanding is that Instantiate doesn't work unless the asset is in the scene. Would appreciate it if someone could tell me how to just place the FBX file on the scene at runtime from my script.
Thanks very much in advance and apologies if I have broken any rules.
Answer by Eric5h5 · Mar 25, 2011 at 06:13 AM
Make prefabs, and instantiate them.
My understanding is that Instantiate doesn't work unless the asset is in the scene.
That's incorrect. The point of Instantiate is to put something in the scene that didn't exist before.
Thank you. I'll try this and get back for a reply in case other people have the same issue. A clarification: Looking at the tutorial for making prefabs, it seems that I have to do them manually through the GUI. I have a lot of models. Is there a way to automate the prefab making process? $$anonymous$$aybe a script?
Probably it is possible with editor scripting, yes, although it's not something I've done.
Ok, I did the Prefab making. However, it gave me the same error (no Renderer attached). I then attached a $$anonymous$$esh Renderer to the prefab and it worked. I then removed that and tried to add it from code and it still worked. Then I removed the prefab and simply added it to my Resources.Load() -ed asset and it still worked. Any reason I shouldn't do it the last way? I understand that packaging all my models inside a Resources folder will blow up my application size. I am looking into Asset Bundles.
Your answer