x


parenting instantiated object

if i have a prefab such as a ball and i want to instantiate it and then parent it under a another object how do i do this to the instantiated game object and not its prefab? example:

var ball : GameObject;

Instantiate(ball,transform.position,transform.rotation)
ball. transform.parent = transform

it does not work because ball is a prefab. how do i do it to the instantiated object and not the prefab it was instantiated from?

more ▼

asked Feb 24 '11 at 05:48 PM

creative72 gravatar image

creative72
143 5 5 14

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

2 answers: sort voted first

Simply assign a variable to hold the instance identity. instead of calling instantiate on its own, you can do:

var myObject : GameObject = Instantiate(ball,transform.position,transform.rotation);
myObject.transform.parent = transform;
more ▼

answered Feb 24 '11 at 05:54 PM

Alec Slayden gravatar image

Alec Slayden
1.2k 1 4 15

:D Was going to write the same thing :P No issues with parenting prefabs :)

Feb 24 '11 at 05:56 PM Izitmee
(comments are locked)
10|3000 characters needed characters left

consider you are going to make "board " as parent and "ball" as a child means....

var myObject : GameObject = Instantiate(ball,transform.position,transform.rotation);
myObject.transform.parent = GameObject.Find("board").transform;
more ▼

answered Feb 25 '11 at 12:03 PM

sriram90 gravatar image

sriram90
460 33 37 47

(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:

x2074
x1668
x1274
x1250
x418

asked: Feb 24 '11 at 05:48 PM

Seen: 2577 times

Last Updated: Feb 24 '11 at 05:48 PM