- Home /
Where to position idle gameobjects referenced in Instantiate
It looks like Instantiate requires that you actually have an initial instance of your object in the scene. I usually just put this "dummy" one somewhere off at Vector3(10000,10000,10000). Is there somewhere better to put it than off somewhere beyond the camera? Where are they supposed to be placed actually?
Answer by aldonaletto · Jan 02, 2012 at 01:29 AM
You should use a prefab rather than a scene object: drag the original instance from the scene to the Project panel to create the prefab, then delete the scene object. Create a Transform variable (let's call it prefab) in your script, and drag the prefab object to it in the Inspector, then use Instantiate(prefab,...) to create instances of this object:
var prefab: Transform; // drag here the prefab that will be cloned
// instantiate the object prefab as usual: Instantiate(prefab, pos, rot);
Yep, perfabs are exactly what you want. They are also GameObjects like any other except they aren't in the scene. Only GameObjects in the scene get updated and rendered, so a prefab is just an instance that can be used as Instantiate / clone source.
Answer by Jace · Jan 02, 2012 at 01:21 AM
Create a prefab of your "dummy" object and then delete the object. Use the prefab in the instantiate rather than the original object.
http://unity3d.com/support/documentation/Manual/Prefabs.html
http://unity3d.com/support/documentation/Manual/Instantiating%20Prefabs.html