Hello, Unity Answers. I have a compiler problem with a reference I made. I know questions like these sound lazy but I’ve been researching for the past hour and frankly, I’m stumped.
I’m working on a Rogue-like game and the problem occurs in my GameManager script. I need a reference to the spawnRoom object to access it’s position, then spawn the player in that room.
The spawnRoom object is a public field of the MapGenerator class (inherits from monodevelop). To allow other classes to access the MapGenerator, I created a singleton pattern so I can access fields of MapGenerator like so:
MapGenerator.instance.field;
The compiler error is in the Start method of my class GameManager : monodevelop.
//Runs on start
private void Start()
{
createSingleton();
spawnPlayer(MapGenerator.instance.spawnRoom);
}
Other notes:
I narrowed the problem down to the spawnRoom object. I get an error when I try to access spawnRoom that reads, Object reference not set to instance of an object. I know what this means, I don’t know why I’m getting the error.
spawnRoom is defined in MapGenerator properly.
The MapGenerator instance is public & static & defined before GameManager starts.
Any help or resources you can point me to would be greatly appreciated.