"Object reference not set to instance of object" but it is
I have tried to import some component from another program to my game but it generated errors. I imported it using the export on the other game and importing the package from my game. errors:
NullReferenceException: Object reference not set to an instance of an object
InfiniteTerrain.Awake () (at Assets/RandomTerrain/Scripts/InfiniteTerrain/InfiniteTerrain.cs:81)
Line 81:
m_splatPrototypes[i].texture.Apply(true);
it also generated the same error on the infinite water script in this line:
m_waterGrid[i, j].transform.parent = InfiniteTerrain.m_terrainGrid[i, j].transform;
I don't know where or what am i suppose to attach the object to. It used to word fine for me but the water didn't work so i imported it again and now it's all broken. Perhaps there is something i didn't import? Please help me. Ethan
Answer by dhore · Apr 14, 2016 at 09:05 AM
My guess is that index i
of m_splatPrototypes
is NULL - since the error says that the referenced object is null (NullReferenceException). And the same would go for the other line - one of the arrays' elements is NULL.
So why did it work on the original before the exportation?
no @dhore it is defined here:
for (int i = 0; i < numOfSplatPrototypes; i++)
{
m_splatPrototypes[i].texture = splat[i];
m_splatPrototypes[i].tileOffset = Vector2.zero;
m_splatPrototypes[i].tileSize = splatTileSize[i];
m_splatPrototypes[i].texture.Apply(true);
}
and here:
for (int i = 0; i < dim; i++)
{
for (int j = 0; j < dim; j++)
{
m_waterGrid[i, j] = Instantiate(Resources.Load("Prefabs/WaterTile", typeof(GameObject))) as GameObject;
m_waterGrid[i, j].transform.position = new Vector3(0, waterHeight, 0);
m_waterGrid[i, j].transform.parent = InfiniteTerrain.m_terrainGrid[i, j].transform;
}
}
What type of variable are the m_splatPrototypes ?
They are "SplatPrototype" if that's a type... Would you like me to send you the code or part of it? Thank you for helping me. Ethan
Your answer
Follow this Question
Related Questions
Obj Ref error at end of code? 1 Answer
Random Chance NullReferenceException: Object reference not set to an instance of an object 2 Answers
Array of dictionaries: "Object reference not set to an instance of an object" 0 Answers
PLEASE HELP!! Object reference not set to an instance of an object at ChangeMasterVolume.Update 1 Answer
[Begginer] [Solved] How to solve a Null Reference Exception 1 Answer