How may I get the children (direct and dependents) of a game object?

Currently I am using Unity for university research purposes, and I am familiar with C# and Unity. In my project, I have a Robot in the hierarchy, and this Robot has many children, and children has their own children. like the following:


Those with “Pivot” at the end of their name, is assigned with the tag called, “RobotPart”.
I am looking for a piece of code that automatically search in the children of the “Robot” and find those with the tag “RobotPart”.
Is there any way to do that?

Finally I want to have access to the properties of those children and control them if necessary. Thanks.
strong text

You can use GameObject.FindGameObjectsWithTag(“RobotPart”).

Best way would be GetComponentsInChildren.

Edit: Just reread your question. Another way would be to do a recursive search. Pseudo code as follows. Note this search could be long an expensive on a complicated hierarchy. Save your project before running too. Recursive functions are notorious for causing infinite loops if mistakes are made.

List<GameObject> RobotParts = new List<GameObject>();

void SearchForParts(Transform current){
    foreach (Transform child in current){
        if(child.tag = "RobotPart"){