- Home /
Instantiate Problem
Whenever I instantiate the Prefab, it doesn't spawn at the position of the sphere but at (0,0,0). why is this? in my script I used "...GameObject.Find("Spawner").transform.position..."
function CreatePlane()
{
switch(random)
{
case 5:
Instantiate( planePrefab, GameObject.Find("Spawner5").transform.position, Quaternion.identity);
break;
case 4:
Instantiate( planePrefab, GameObject.Find("Spawner4").transform.position, Quaternion.identity);
break;
case 3:
Instantiate( planePrefab, GameObject.Find("Spawner3").transform.position, Quaternion.identity);
break;
case 2:
Instantiate( planePrefab, GameObject.Find("Spawner2").transform.position, Quaternion.identity);
break;
case 1:
Instantiate( planePrefab, GameObject.Find("Spawner1").transform.position, Quaternion.identity);
break;
}
}
Without seeing more code it's going to be hard to help you.
Answer by Mike 3 · Jun 21, 2010 at 08:19 AM
Make sure your script can actually find the Spawner objects first. print out whether or not the return from Find is an actual object.
Next, check the position of that object (via another print) - it's possible that you could have duplicates at Vector3.zero that you didn't know about
Answer by Jason Hamilton · Jun 21, 2010 at 08:03 AM
Edit: removed the script from here and put it into the question
Answer by Thomas Hentschel Lund · Jun 21, 2010 at 10:05 AM
That is also my guess. Your code GameObject.Find("Spawner1") doesnt return a valid game object and thus the Instantiate falls back to spawning your object at 0,0,0
@$$anonymous$$, no offense, but your reply is basically the same as @$$anonymous$$ike's (as your first line says). It doesn't really warrant a new Answer - if you had any $$anonymous$$or updates, it should go as a comment to another Answer.
Ah - none taken. Need to getting used to answering more stuff here "the right way"
Answer by Tryggvienator · Mar 23, 2012 at 03:35 PM
Is it possible that the item you are instantiating has animation attached to it. If so, try turning the animation off.
Your answer
Follow this Question
Related Questions
Scripts of instantiated objects 1 Answer
How to have unique instances of script on multiple instances of prefab? 1 Answer
making prefabs at runtime? 2 Answers
Instantiate A Prefab 1 Answer