- Home /
Question by
xbennettx821 · Jul 10, 2011 at 10:34 PM ·
javascriptspawnchild
How do I spawn a prefab to be the child of a mesh?
With javascript, I'm trying to instantiate a prefab to be the child of a mesh that is already spawned. By doing this I'm hoping that when the mesh rotates or moves the prefab will follow-up on the action. How might I go about doing this?
Comment
Answer by Waz · Jul 10, 2011 at 11:14 PM
Set the parent:
newobject.transform.parent = otherobjectwithmesh.transform;
Note that a Mesh (actually a MeshRenderer) is a component in a GameObject, and every GameObject has a transform component such that the parent members form the gameobjects into the hierarchy. So you don't make children of a mesh directly but rather through the transform of their GameObject.
Your answer
![](https://koobas.hobune.stream/wayback/20220612140618im_/https://answers.unity.com/themes/thub/images/avi.jpg)