List suddently becomes null

Hey, I’m trying to create some randomly generated rooms in a tilemap. I’m very early in the process and I only have 2 scripts. In my first script, I create a list called filledPos to store the cordinates of my existing rooms, but it keeps saying in my Detect-function that it is null!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Generator : MonoBehaviour {

	public List<Vector2> filledPos = new List<Vector2>();
	public GameObject room;
	public Vector2 maxSize;
	public int roomSize;

	void Start () {
		Spawn (maxSize / 2 * roomSize);
	}

	public void Spawn(Vector2 pos) 
	{
		Instantiate (room, pos, Quaternion.identity).GetComponent<SpawnRooms> ().Detect (maxSize / 2);
	}
}

OTHER SCRIPT:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnRooms : MonoBehaviour {

	public Generator generator;

	void Start () {
		generator = GameObject.FindWithTag ("GameController").GetComponent<Generator> ();

	}

	public void Detect (Vector2 gridPos) 
	{
		//Spawn this room

		//Spawn Connected Rooms
		List<Vector2> checkPos = new List<Vector2>(){new Vector2 (gridPos.x + 1, gridPos.y), new Vector2 (gridPos.x, gridPos.y + 1), new Vector2 (gridPos.x - 1, gridPos.y), new Vector2 (gridPos.x, gridPos.y - 1)};

		for (int i = 0; i < checkPos.Count; i++) {
			print (checkPos *);*

_ if (!generator.filledPos.Contains(checkPos*))_
_
{_
_ //generator.Spawn (checkPos);
}
}
}
}*
If I test for the List in Start() of any of the scripts, it works. But when I move into Detect() it’s null. I’ve tried to create the list in Awake() and lot’s of other things, but it does not make any difference.
The List is only used the times you see it here._

You are calling Detect() before Start() in SpawnRooms class. generator is therefor null when Detect is called. You can put generator = GameObject.FindWithTag ("GameController").GetComponent<Generator> (); inside Detect() to fix it.