Null Reference Excepting :Object reference not set to an instance of object while changing text of 3D text

Hey guys i have this prefab structure …
Prefab

  1. Sphere
  2. Clyinder
  3. Sphere
  4. 3D text…
    Now i instantiate the prefab at runtime from this code :

GameObject go = (GameObject)Instantiate(Resources.Load(“Prefab1”));

After instantiating the prefab i want to change the text of 3D text depending on click of which element it is instantiated. And this is what i have tried as suggested by many post out here.But its giving me the Null reference exception.

go.GetComponent().text=symbol;

Can anyone suggest what the problem is there. ?

GetComponent usually takes an argument which is the name of the component you are trying to access. In your case that’s probably the TextMesh component.

go.GetComponentInChildren().text=symbol;

With this its working completely fine. and yeah the nullreferenceexception was may be the font was missing in the inspector.Why unity dont let me specify < TextMesh > before the “()”.I tried it many a times but it doesn’t.