Object reference not set to an instance of an object (singleton)

Hello!

I have a class Main. In the start method of that class i call a method InitMainScreen. InitMainScreen sets some starting conditions (enables the main menu, clears scene of garbage objects and instantiate a player):

void Start () {
	instance = this;
	Screen.orientation = ScreenOrientation.Portrait;
	InitMainScreen ();
}
public void InitMainScreen() {
	Instantiate (player, new Vector3 (1, -3.51f, 0), transform.rotation);
	TerrainManager.instance.ResetScene ();
	GuiManager.instance.EnableMainMenu ();
}

My issue is that the line TerrainManager.instance.ResetScene (); gives the error “Object reference not set to an instance of an object”

This is really confusing to me, because in the TerrainManger i have a public static TerrainManager instance that i during start set to the same class:

	public static TerrainManager instance = null;

	public GameObject wallPair1;
	public GameObject wallPair2;
	public GameObject obstacle;
	public GameObject startFloor;

    private float rawDistanceClimbed;

	void Start() {
		instance = this;
	}

	public void ResetScene() {
		startFloor.transform.position = new Vector3 (0, -4.891f, 0);
		wallPair1.transform.position = new Vector3 (0, -12, 0);
		wallPair2.transform.position = new Vector3 (0, 0, 0);

		GameObject[] garbageCollector;
		garbageCollector = GameObject.FindGameObjectsWithTag ("obstacle");
		foreach (GameObject obstacle in garbageCollector) {Destroy (obstacle);}
		rawDistanceClimbed = 0;
	}

This way of referencing classes usually work for me but i cant figure out why i get this error now?

EDIT: i think i have this issue because the TerrainManager class is initialized after the Main class? If this is the case i guess my only option is to set the starting environment manually… :confused:

Set the instance on Awake and check if have a GameObject with a TerrainManager attached. You can set the TerrainManager to execute before all other scripts in the Script Execution Order Settings.