bad children

I am trying hard, but failing hard as well :frowning:
I have a transform named “firsttransform” and I am randomly assigning it a child object (from a list of 10 possibilities). What I want to do is be able to say something like "get the child of “firsttransform” , whatever it is, and move it to “secondtransform”. The movement bit is fine, but I can’t figure out how to say “get the child”.

Is there something like

firsttransform.child = firstchild ?

I need to lie down :frowning:

No, because there can be any number of children. You can bypass the entire issue though: since you’re assigning the child object to “firsttransform”, that must mean you already have a reference to the child object. You can use that reference to move it to “secondtransform”.

–Eric

If there is only one child you can do something like this:

foreach (Transform myChild in transform)
{
		myChild.parent = yourSecondTransform;
}

(*assumes you have assigned “yourSecondTransform”)

What about transform.GetChild?

Does that help?

No, that function has been deprecated. :slight_smile:
If you need to access the children of a transform, use the method I showed. It is the first example script in the Transform documentation here