- Home /
Instantiated objects not visible or rendering
I am instantiating some objects when an object is clicked on. My process for making the prefabs was to take the model once it had been dragged into the hierarchy, textured, and scripts added, and drag it into an empty prefab. Then in the script I have this code:
//transit system assets var busNPC: Transform; var busStop: Transform; var insBus: Transform; var insStop: Transform; var transit_state: boolean; //true=on var trans_stantiated: boolean;
function Update () { if(transit_state && !trans_stantiated) { print("Instantiating"); insBus = Instantiate(busNPC); Debug.Break(); insStop = Instantiate(busStop); trans_stantiated = true; } else if(!transit_state && trans_stantiated) { Destroy(insBus); Destroy(insStop); trans_stantiated=false; } }
What am I doing wrong here? I've investigated the state after instantiation, and this shouldn't be an issue. The prefabs, when dragged manually into the hierarchy, appear properly, correct rotation, correct position. After the Debug.Break(), everything is exactly right on the objects. What did I do wrong?
I'm not sure (yet at least) why the things aren't displaying properly, but the Destroy code is wrong - you need to destroy insBus.gameObject and insStop.gameObject ins$$anonymous$$d otherwise it'll just give you errors
@$$anonymous$$ike should he be instantiating a Transform?
I've tried instantiating the gameobject now. No effect. Still will not display.
Put a debug statement with the Destroy() calls to see if they're being destroyed too soon.
Answer by Zeroth · May 27, 2010 at 07:45 PM
The problem was the prefabs had the wrong position, and thus weren't visible. Nothing special at all.