- Home /
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);
}
Answer by Cripple · Sep 04, 2012 at 09:50 PM
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.
SWEET. It turns out that player didnt have that script, it was some other object and i totally forgot that i assigned it to a different object lol thanks.
Answer by Screenhog · Aug 29, 2012 at 11:18 PM
Can't you just do "transform" instead of "this.transform"? I don't know if the word "this" is actually used anywhere in Unity.
That still gives me the same "object reference not set to instance" error.
this. is accepted by Unity, just as the keyword new (new Vector3) is accepted in uJS. They are not required, but they work =]
Sorry, I cannot help with your problem in C# though, it is merciless if you don't declare things as it likes :(
unless it's something simple like the method renderChunk is not set as public void?
Your answer
Follow this Question
Related Questions
Acces to other object trigger thru other object script 0 Answers
how to scale the transport? 1 Answer
I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers
How to move an object to your current positon? 0 Answers
How do I restrict game to only instantiate 1 instance of object? 1 Answer