I have the problem, that i want to add objects to a list which is part of an array. i was searching in the forum, but could not find a correct solution, because mostly the problem was in the instantiating of the list and that is what i have done correct(as far as i can say):
the error comes in line 27 of the 2nd part of code.
so here is the part of my code that makes the problem:
public class PlaygroundCreatorWorkingConcept : MonoBehaviour
{
public int height;
public int width;
List<WallInformation> WallInformations = new List<WallInformation>();
List<WallInformation>[,] WallInformationSmall;
}
public class WallInformation
{
public Coord coordinate;
public bool isWall;
public float floorHeight;
public float ceilingHeight;
public WallInformation(Coord newCoordinate, bool newIsWall, float newFloorHeight, float newCeilingHeight)
{
coordinate = newCoordinate;
isWall = newIsWall;
floorHeight = newFloorHeight;
ceilingHeight = newCeilingHeight;
}
}
void Awake()
{
WallInformationSmall = new List<WallInformation>[width / 10, height / 10];
for(int i = 0; i >= width / 10; i++)
{
for (int j = 0; j >= height / 10; j++)
{
WallInformationSmall[i, j] = new List<WallInformation>();
}
}
}
this is the top of the programm with all important thing for the question
public void SetWallInformations()
{
for (int x = 0; x < width; x++)
{
for (int z = 0; z < height; z++)
{
WallInformations.Add(new WallInformation(new Coord(x, z), isWall[x, z], floorWorld[x, z], ceilingWorld[x, z]));
}
} //scheint bis hier zu funktionieren, da er bei small 50*50 = 2500 informationen füllt.
foreach (WallInformation WallInformation in WallInformations)
{
Debug.Log(WallInformations.Count);
Debug.Log(WallInformation.coordinate.tileX);
Debug.Log(WallInformation.coordinate.tileZ);
Debug.Log(WallInformation.isWall);
Debug.Log(WallInformation.floorHeight);
Debug.Log(WallInformation.ceilingHeight);
int i = 0;
int j = 0;
if (WallInformation.coordinate.tileX >= i + 0 && WallInformation.coordinate.tileX <= i + 10)
{
Debug.Log("Bin Hier1.");
if (WallInformation.coordinate.tileZ >= j + 0 && WallInformation.coordinate.tileZ <= j + 10)
{
Debug.Log("Bin Hier2.");
WallInformationSmall[i, j].Add(WallInformation);
}
else
{
j++;
//return;
Debug.Log("Bin Hier3.");
}
}
else
{
i++;
j = 0;
//return;
}
i = 0;
Debug.Log("Bin Hier4.");
}
}
the problem is that the line below Debug.Log(“Bin Hier2”); does give me this error:
NullReferenceException: Object reference not set to an instance of an object