If (List.Contains (Vector3){} give a Null Ref????

Okay I have 2 scripts, one generates a list of Vector3’s. The second checks to see if a Vector3 exists on the list. No errors on console till I try to run the game. but when I do it throws a null ref.
both scripts are using “using System.Collections.Generic;”

script 1:

    public class Script1 : MonoBehaviour {
    	public List<Vector3> testList= new List<Vector3>();
    ..............
    	void runonce(){
    		for (int ix = 0; ix < 10; ix++) {
    			for (int iz = 0; iz < 10; iz++) {
    				for (int iy = 0; iy < 10; iy++) {
    					current = new Vector3 (ix, iy, iz);
    					if (testList.Contains (current)) {
............................................

 }

this first script runs fine on its own and produces no errors. however, script 2…

public class Script2: MonoBehaviour {
	GameObject object;
	Script1 script1;

void Start () {
            GameObject object = GameObject.Find("object");
            Script1 script1 = object.GetComponent<Script1>();
}
.......................
checkForChanges(){
Vector3 thisVoxelPosition = this.transform.position;
		int thisX = Mathf.RoundToInt (thisVoxelPosition.x);
		int thisY = Mathf.RoundToInt (thisVoxelPosition.y);
		int thisZ = Mathf.RoundToInt (thisVoxelPosition.z);

checkedSpace = new Vector3 (thisX, thisY, thisZ + 1);
		if (script1.testList.Contains (checkedSpace)) {
			checkFront = 0;
		} else {
			checkFront = 1;
		}

}

Btw I know the Mathf.RoundToInt stuff is probably not needed, and I have tried this with
float thisX = thisVoxelPosition.x; ect…
no good. Null Ref on the line
if (script1.testList.Contains…

I’ve also tried if (script1.testList.Exists…

When you get a null ref error, you should Debug.Log all variables on the error throwing line to see what actually is null. That’s basic debugging. You have to know exactly what is broken before you can fix it.

I bet your script1 variable is null when you try to use it in checkForChanges().

Script1 script1;  // field called script1
 
 void Start () {
             GameObject object = GameObject.Find("object");
            // new local variable called script1 that only exists in this method
             Script1 script1 = object.GetComponent<Script1>();
 }

The whole thing might work if you just assign to the field instead of declaring a new local variable

script1 = object.GetComponent<Script1>();

Also i wouldn’t suggest having a variable called ‘object’ because that’s also a class name.