C# Specifying which Children to add to the Array

Hi everyone, is there a way to get GetComponentsInChildren(); to specify which children to add to someTransformArray? I want to add some of the gameobject’s children to the array but not all of them.

Public Transform[] someTransformArray;

void Awake(){
someTransformArray = GetComponentsInChildren<Transform>();

If I understand correctly, you want to filter the return values from GetComponentsInChildren() to only select the values of type Transform and set it equal to an array?

Try this:

someTransformArray = GetComponentsInChildren().OfType<Transform>().ToArray();

It reads almost like English; gotta love LINQ :slight_smile:

Note: You may need to include using System.Linq to use OfType().