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.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
1 Person is following this question.
Getting the topmost parent
Very Erratic behavior when parenting an object
Problem with the direction of the raycast when rotating
Why is parenting not working?
Order of Update(), Awake(), etc of gameobjects and their child gameobjects