How do you dynamically parent gameobject at runtime?
Answer by Mike 3
Mar 15, 2011 at 07:49 AM
You need to use the parent property on the transform:
transform.parent = anotherTransform;
How do you reference a dynamically created object though
var instantiated = Instantiate(prefab) as GameObject; transform.parent = instantiated.transform;
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
1 Person is following this question.
Getting the topmost parent
Very Erratic behavior when parenting an object
How to use unityeditor and where I need it?
Instantiate Terrain Object as child of Empty Game Object
Find position of the GameObject this script is attached to.