Getting components in children

Hi all… I have the following code

GameObject g  = Resources.LoadAssetAtPath(loadPath,typeof(GameObject)) as GameObject;
Transform[] all =  g.GetComponentsInChildren<Transform>()
foreach(Transform tt in all){
 
  Debug.Log(tt);

}

I know I have loaded the gameobject g. Since I didn’t get a null when I tested.
But I dont seem to get anything else that is under g.
I keep on getting Null on tt

I know it would work if I just bring instantiate the gameobject to scene. But I am wondering if I can do it without instantiating it ?

Hi!
I think you are correct in assuming that you have to instantiate the object in order to be able to inspect the hierarchy etc.

there is nothing wrong with the code after loading the GameObject g. If you are 200% sure g is not null, maybe put the part after that in an IEnumerator that waits for the next fix update, although I cant see any reason why, if g is not null the rest should load fine into that array? Just taking a wild guess here.

g is a prefab. As far as I know, you can’t access children of a prefab. It is necessary to create an instance.

I didnt think about the prefab issue, you are correct.

Thanks all for the input… eventually I instantiate the gameobject into the scene. Since I was under time pressure to finish off the tool.
But I guess it is true I can only access components in scene. Unless there is a way to go about it and some one would share that information