- Home /
Set parent in the code (create GameObject hierarchy programatically)
Hi,
I use the code
// Set parent object
floor_part.transform.parent = transform.parent;
To set the parent for the generated GameObject
. The problem is that in the editor I do not see the hierarchy created - is that just the editor problem? Am I doing something wrong?
See the attached picture.
BR STeN
Yes, you're doing something wrong, but without more of the script it's not obvious what. The hierarchy will immediately show parenting changes if they are actually happening.
Answer by robertbu · Mar 01, 2014 at 04:26 AM
Taking an educated guess, you want:
floor_part.transform.parent = transform;
If the script is running on 'Floor', it's parent will be null, so this code sets a null parent. You want to set the parent to the transform of this game object.
Your answer
Follow this Question
Related Questions
Manipulating Instanced Object 2 Answers
GameObject parenting during runtime 1 Answer
Insantiate object to parent without changing scale? 0 Answers
How do I find a child object in a hierarchy of children? 1 Answer
Particle offset on parent.transform 0 Answers