x


"The prefab you want to instantiate is null" what am I doing wrong nested...?

I have a game object that's created at runtime, I've attached a script to it after creating it, that script holds an instantiation of an object should something happen.... because this game object is created at runtime, and the script is attached after it's creation, I can't access the inspector to set the prefab...

So I'm trying to add it in code...

something like this: this script is attached to the object that's waiting for the condition to create the prefab:

var PS_top_ordered : GameObject;
PS_top_ordered = GetComponent("PS_top_Ordered");

And later, inside the update (){ is this:::

if (Input.GetKeyDown ("a")){

    Instantiate(PS_top_ordered, transform.position, transform.rotation);

}

more ▼

asked Dec 23 '10 at 03:46 PM

dissidently gravatar image

dissidently
450 50 55 60

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

1 answer: sort voted first

The GetComponent function returns a component, not a prefab of a game object. Yet you assign it into PS_top_ordered which is a game object.

I can't even believe the Javascript compiler allows you to do that! Use C# :)

more ▼

answered Dec 23 '10 at 03:53 PM

taoa gravatar image

taoa
1.6k 8 13 34

so how do I set the variable PS_top_ordered to the prefab "PS_top_Ordered" which is sitting in my Project?

Dec 23 '10 at 04:12 PM dissidently

If I do it like this, it tells me I'm trying to make the variable into a string>>>> var PS_top_ordered : GameObject; PS_top_ordered = ("PS_top_Ordered");

Dec 23 '10 at 04:14 PM dissidently

Instead of assigning PS_top_ordered in your script, since your script should be attached to a game object, slide (click->drag) your PREFAB named PS_top_ordered into the property in the inspector, then you can instantiate at will! :)

Dec 23 '10 at 04:21 PM taoa

I can't do that. the Script is nested. Sits on a game object that's created at runtime, from a prefab. The script is added to the instantiation of the prefab at game start using "addcomponent" which works, (pulling the script from the inspector to attach to the newly created "parent" prefab) but getting this second layer deeper, and pulling a prefab from the inspector doesn't?

Dec 23 '10 at 04:47 PM dissidently

The Javascript compiler doesn't allow it, if you use #pragma strict.

Dec 23 '10 at 05:12 PM Eric5h5
(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:

x5098
x1683
x1260
x36

asked: Dec 23 '10 at 03:46 PM

Seen: 1317 times

Last Updated: Dec 23 '10 at 03:46 PM