- Home /
Instantiated prefab loses components
I instantiated a prefab in a script. The GameObject that is created doesn't have any of the components from my prefab in the project view. My prefab is suppose to have a rigidbody and a box collider but when I instantiate it it has neither. I tried just creating them and setting them to the ones they should be but it's telling me the value I am trying to take them from is a read only variable(a global variable set to a gameobject in project view). I tried creating the whole thing in the script but then I couldn't find a way to edit the box collider size and center variables. A way to do that would allow me a work around but a solution to the problem of the prefab losing its components would be ideal. Sorry if this question appeared somewhere else but I looked and couldn't find it.
That's strange, never had that problem before. I'm guessing you have the prefab in the project window that has all the components attached. If you add this to your hierarchy by dragging it, are the components attached to the game object? The game object in the hierarchy should have blue (ins$$anonymous$$d of black) text..
Answer by kretchfoop · Dec 13, 2011 at 07:26 AM
I was trying to instantiate it using a script with it as a variable in the script (in the project view). I got around it with kind of a hack job of making an actual version of the prefab in the hierarchy off camera and instantiating that. Seems to be working fine.