object not set to instance..........again.

So i have had this issue before, and it has been dealt with in a different scenario, however i can’t come to a solution for this one. when i call a function in another script it tells me that it needs to be set to an instance of an object, and im assuming its refering the the “this.transform” part. What’s a work around for this?

 else if(!terrain.chunksToRender.Contains(this.transform)) { 
			
			terrain terrainScript = player.GetComponent<terrain>(); 
			terrainScript.renderChunk(this.transform); //here lies the issue
			terrain.chunksToRender.Add(this.transform);
			
		}

Can’t you just do “transform” instead of “this.transform”? I don’t know if the word “this” is actually used anywhere in Unity.

Hi,

It must be terrainscript which has a null reference. Are you sure that you have attached the script terrain to your GameObject player ?

If you want to debug, just try something like this :

terrain terrainScript = player.GetComponent<terrain>(); 
if( terrainScript == null)
{
         Debug.Log("terrain script not found");
}
else 
{ 
         terrainScript.renderChunk(this.transform);
         terrain.chunksToRender.Add(this.transform);
}

You should also give your script/class name a name starting with a upper case, it is a C# convention. Here you should have “Terrain” instead of terrain.