- Home /
How to move the parent object to a child of one of its children?
I want a parent Game Object to parent itself to one of its children. How do I do this?
Answer by Joxev · Mar 05, 2020 at 02:46 AM
Can you explain in more depth? A parent GameObject is already a parent of it's children. Do you want the parent to become a child of it's children?
Yes. I want to move a parent to become a child of it's children. how to do this?
Answer by tecses1 · Mar 05, 2020 at 04:55 AM
If you know exactly what GameObject you want to set as the parent (Make your current parent a child of) then you can just use a reference of it.
Transform child; //Set the child object
transform.SetParent(child); //Set this transform to be a child of that object.
If you're unsure what child specifically... It becomes a much harder problem. If you have a way to identify it however, you could later use:
Transform child = GameObject.Find("Object Name").transform;
String finds are messy though, I'd recommend something a little more deterministic.