How to get children from a Parent and not get the children of the children too

i have this code

GameObject AC = GameObject.Find(_parent); //Find the Constutiency object

Transform[] acs = AC.GetComponentsInChildren<Transform>();

i just need to get the child objects of the parent but the child objects too have children and those child objects of the child object are also grabbed.

i read this post link text

i have iterated through transform to get the children, is this the only way to do it ?

Well, the answer was in the linked post :

GameObject AC = GameObject.Find(_parent); //Find the Constutiency object

foreach (Transform child in AC.transform)
{
  //child is your child transform
}

You can use this:

GameObject AC = GameObject.Find(_parent); //Find the Constutiency object
 
Transform[] acs = new Transform[AC.transform.childCount];

for (int i = 0; i < AC.transform.childCount; ++i) {
    acs *= AC.transform.GetChild (i);*

}

Does childCount also count grandchildren? If it doesnt perhaps you can use the figure returned to iterate your list hopefully skipping all grandchildren.

I had another thought, perhaps if you just GetChild the First Child you can then use GetSiblingIndex to discover the children on the same level.

Never tried this, its just a concept.

If I understand it correctly, you want all the immediate child transforms of parent. In that case, this question seems to provide a solution.

If what you want is to get components only in the direct children then this forum thread seems to have the best solution (3 versions, towards the bottom). To summarize, iterate through the child transforms of parent’s transform and put the components in a List.