x


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;
    }
}
more ▼

asked Jun 21 '10 at 07:18 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

Without seeing more code it's going to be hard to help you.

Jun 21 '10 at 07:20 AM Tetrad
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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

more ▼

answered Jun 21 '10 at 08:19 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

(comments are locked)
10|3000 characters needed characters left

Is it possible that the item you are instantiating has animation attached to it. If so, try turning the animation off.

more ▼

answered Mar 23 '12 at 03:35 PM

Tryggvienator gravatar image

Tryggvienator
61 4

(comments are locked)
10|3000 characters needed characters left

Edit: removed the script from here and put it into the question

more ▼

answered Jun 21 '10 at 08:03 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jun 21 '10 at 10:05 AM

Thomas Hentschel Lund gravatar image

Thomas Hentschel Lund
329 3 4 14

@Thomas, no offense, but your reply is basically the same as @Mike's (as your first line says). It doesn't really warrant a new Answer - if you had any minor updates, it should go as a comment to another Answer.

Jun 21 '10 at 02:20 PM Cyclops

Ah - none taken. Need to getting used to answering more stuff here "the right way"

Jun 24 '10 at 11:25 AM Thomas Hentschel Lund
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3330
x1674
x1256

asked: Jun 21 '10 at 07:18 AM

Seen: 1473 times

Last Updated: Mar 23 '12 at 03:36 PM