- Home /
Instantiate as child of target object
i need to instantiate object as summonPoint child, but my script on root player part, how can i move instantiated object to target object? Simple transform.parrent not working :(
Answer by aldonaletto · May 09, 2013 at 01:55 PM
You can find the object "summonPoint" by name with transform.Find, then child the new object to it - like this:
...
var summon = transform.Find("Torso/LegPoint/summonPoint");
newObject.transform.parent = summon;
...
You must specify the correct path, or the object will not be found. If you don't want to worry about the exact path, add the function below to your script - this function can find a transform by name down in the hierarchy:
static function FindInChildren(name: String, tf: Transform): Transform {
if (!tf.gameObject.active) return null;
var tgt = tf.Find(name);
if (!tgt) for (var child in tf){
tgt = FindInChildren(name, child);
if (tgt) return tgt;
}
return tgt;
}
Find the "summonPoint" and make it the new object's parent this way:
...
var summon = FindInChildren("summonPoint", transform);
newObject.transform.parent = summon;
...
Can't use Transform.Find in C# :( can you please repost something similar in C?
It is small 't'.
transform.Find("Torso/LegPoint/summonPoint");
Your answer

Follow this Question
Related Questions
Instantiating prefab at child (spawnlocations are arrays) 2 Answers
Checking if object intersects? 1 Answer
How to find and remove the last child of parent? 1 Answer
access child of a gameobject 7 Answers
prefab question 1 Answer