- Home /
Question by
Donnell-007 · Dec 11, 2012 at 06:16 PM ·
gameobjectinstantiateparentchildrename
Renaming Child Objects during Instantiate?
When Instantiating an object, how do you rename the child objects within the gameobject (parent) that is being instantiated?
Basically I have this:
- MainObject
ChildA
ChildB
When I instantiate and use name to rename the obect, it renames the parent object, like this:
- MainObject_DifferentName
ChildA
ChildB
But I want to do something like this:
MainObject
ChildA_2
ChildB_2
Comment
i think you need THIS long answer
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
pls vote up any useful long answers!
Answer by cassius · Dec 12, 2012 at 05:15 PM
I think you will need to get the children of the instantiated object. Maybe something like this?
instantiatedObject.name = "MainObject";
for(var child : GameObject in instantiatedObject) {
if(child.name != "MainObject");
child.name = child.name+"_2";
}