How to Disable Child of Child but not Child

I decided dragging 40 objects in to a script by hand was too much effort, so I spent 2 hours figuring out how to do it by script instead.
I wanted to disable all 40 objects, but not their folder, and not the parent folder.

It looks like a number of people have asked, so now, here you go. I am sure it can be used for basically any component instead of just gameObject.SetActive.

public GameObject _everythingObject;
//set the everythingobject in your script to be the grandparent.

foreach (Transform child in _everythingObject.transform)
{
    for (int i = 0; i < child.transform.childCount; i++)
    {
        child.transform.GetChild(i).gameObject.SetActive(false);
    }
}

Set the _everythingObject to be the grandparent.
This code will then find all children of the grandparent (the parents), and execute the code on all children in that parent.

For example, I assigned _homeDefAssets as _everythingObject.
_homeDefAssets has four children
Each of those children has between 4 and 20 things in it.
So all grandchildren of _homeDefAssets are now SetActive(false).

If anyone knows how to iterate to the grandchildren past this, please put it in here.

If it shouldn’t work this way, uh… but it totally does. I’m going to go see if this can populate Canvasgroups for the 40 objects I just set inactive.

bool doWeWantInactiveObjectsToo = true;
int requiredLayersMask = LayerMask.GetMask("Characters", "Radar");

foreach (Transform descendant in
    transform.GetComponentInChildren<Transform>(doWeWantInactiveObjectsToo))
{
    // optionally exclude the root/parent object
    if (descendant == transform)
        continue;

    // optionally exclude the first generation of kids
    if (descendant.parent == transform)
        continue;

    // optionally require a certain layer
    if (0 == ((1 << descendant.gameObject.layer) & requiredLayersMask))
        continue;

    // optionally require some particular component
    if (!descendant.TryGetComponent<SomeComponentWeNeed>(out var component))
        continue;

    // optionally require a certain tag
    if (!descendant.gameObject.CompareTag("neededTag"))
        continue;

    FinallyDoSomethingWith(descendant);
}