C# Null Reference Exception in Custom Function

Hi everyone, I’m trying to create a function that a finds a gameobject with a tag and then adds the gameobject’s children to a transform array. When I run the script the console gives me a null reference exception and it points to line 5. Any reason why? I don’t see anything that is null here.

public Transform[] someTransformArray;

	void FindGameObjectsChildrenByTag(string tag, Transform[] transformArray){
	GameObject go = GameObject.FindGameObjectWithTag(tag);
	transformArray = go.GetComponentsInChildren<Transform>();//Null Reference Exception

        void Awake(){
FindGameObjectsChildrenByTag("someTag", someTransformArray);

It’s very likely that GameObject go is null. You should always do a null check before using a value that you think could be null. Think to yourself, what happens if GameObject.FindGameObjectWithTag doesn’t find anything?

GameObject go = GameObject.FindGameObjectWithTag(tag);
if (go != null)
    transformArray = go.GetComponentsInChildren<Transform>();
else if (Debug.isDebugBuild)
    Debug.LogError(string.Format("No GameObject with tag {0} was found.", tag));