C# GameObject.FindGameObjectsWithTag Children

Hi everyone, I have two gameobjects that are Tagged and I want to access their children. How exactly do I do that? I know there’s a way to find the gameobjects with GameObject.FindGameObjectsWithTag and you can access children with GetComponentsInChildren(); but I’m not sure if you can combine the two.

public Transform someGameObjectChildren;
public Transform someGameObjectChildren2;

void Awake(){
//pseudo code below
//someGameObjectChildren = GameObject.FindGameObjectsWithTagAndChildren(someGameObject.children);
//someGameObjectChildren2 = GameObject.FindGameObjectsWithTagAndChildren(someGameObject2.children);

You could just do a function that combine both :

static T[] FindObjectByTagAndComponent<T>(string tag)
    GameObject go = FindGameObjectWithTag(tag);
    T[] children = go.GetComponentsInChildren<T>();

    return children;

Hope it helps :slight_smile: