So I have a simpel question. I have a empty gameobject(let’s call it cat), which has 7 chldren I don’t know which. I have them inside of another empty gameobject(let’s call this dog). I want to detach the children from the cat but keep them in the dog. When using the transform.detachChildren() the children are being detached but lose their place in the hierarchy(they are being placed outside of my dog). So is there any way to set the parent of children of a parent. Like I am changing there parent to dog? I don’t know the chldren but do know the dog and cat, so I can’t just set the parent of each child.
Hope this clarifies my question sufficient. Thanks for the help!
Make a list of the child objects before you detach them:
List<Transform> childrenTransforms = new List<Transform>();
foreach (Transform child in transform)
{
childrenTransforms.Add(child);
}
transform.detachChildren();
foreach (Transform child in childrenTransforms)
{
child.parent = dog.transform;
}
Hopefully that helps,
Cheers