GetComponent started returning nulls

Hi All,

Isololated problem to GetComponent returning nulls. Pulled code fragment from production and made a test case:

	// Use this for initialization
	void Start () {

		FishModel.Type fishType = FishModel.Type.SUNFISH;
		GameObject fishGO = FishModel.createFish( fishType, lake, turnManager );

		FishModel fish = fishGO.GetComponent<FishModel>();
		FishModel fish2 = fishGO.GetComponentInChildren<FishModel>();
		FishModel fish3 = (FishModel) fishGO.GetComponent( "FishModel" );
		BoatSensors sensor = fishGO.GetComponent<BoatSensors>();
		Counter counter = fishGO.GetComponent<Counter>();
	}

All the fish give error “Object reference not set to an instance of an object”
Other components return correctly![alt text][1].
One test run, all the fish components were correct?
The fish prefab has not been touched in months.
We say the FishModel script is there and enabled.

We need a second pair of eyes to see what we are overlooking.

Cheers

This seems fishy.

What is difference between

FishModel fish = fishGO.GetComponent<FishModel>();

and

FishModel fish3 = (FishModel) fishGO.GetComponent( "FishModel" );

If your newly initiated mesh components are not dynamic, why not create a helper mono class with linked reference already on the prefab?

Put this in the Awake () like this

void Awake()
{
            FishModel.Type fishType = FishModel.Type.SUNFISH;
5.         GameObject fishGO = FishModel.createFish( fishType, lake, turnManager );
}




void Start () {

 

 
         FishModel fish = fishGO.GetComponent<FishModel>();
         FishModel fish2 = fishGO.GetComponentInChildren<FishModel>();
         FishModel fish3 = (FishModel) fishGO.GetComponent( "FishModel" );
10.         BoatSensors sensor = fishGO.GetComponent<BoatSensors>();
         Counter counter = fishGO.GetComponent<Counter>();