So I’m working on something to create an array to store the data for locations you can interact with on a map, and I’m using an object called landmark which houses all relevant data needed when the game is saved and loaded.
The problem is that the object itself is recognized as null, which has made it impossible for me to store in an array (a NullReferenceException pops up every time).
Here’s some example code, hopefully someone can figure out whatever mistake I’m making.
//an example of the landmark class
public class landmark : MonoBehaviour {
public int sectorNumber;
public int landmarkID;
public float positionX;
public float positionY;
}
//a test script showing the issue
public class landmarkTest : MonoBehaviour {
landmark[] testArray;
landmark landmarkTest;
void Start()
{
testArray = new landmark[1];
landmarkTest = new landmark();
testArray[0] = landmarkTest;
print(testArray[0]);
}
//when the print command runs, it prints "null" to the console.
//however, when I print testArray, it prints "landmark[]"
}
Note: In case you couldn’t tell, I’m a beginner to both C# and Unity so the answer might be blindingly obvious.