Object reference not set to an instance of the object... but it is C#

Ignore the insanely log code I was to lazy to crop out exactly where the issue was so i’ll explain it

on line 51 the error is called

The only objects on that line are the Transform target which is created locally and the GameObject that is being found by its tag which is instantiated at “Runtime” <— this might be the problem but I would like someone to confirm I didn’t do something really stupid.

And yes an object does exist with the Tag “Teleporter” I have 100% confirmed that.

Script (sorry for not cropping out just what you need, just in case showed the whole thing)

using UnityEngine;
using System.Collections;

public class WallGenerator : MonoBehaviour {

	public GameObject[] outerWalls;
	public GameObject[] innerWalls;
	public GameObject wall;

	public Material[] materials;

	public NavMeshPath path;

	void Start()
	{
		foreach (GameObject item in outerWalls) 
		{

			string mat = PlayerPrefs.GetString ("towerName");
			switch (mat) {
			case "Wooden Tower":
				wall.GetComponent<Renderer> ().material = materials [0];
				item.GetComponent<Renderer> ().material = materials [0];
				break;
			case "Stone Tower":
				wall.GetComponent<Renderer> ().material = materials [1];
				item.GetComponent<Renderer> ().material = materials [1];
				break;
			case "Metal Tower":
				wall.GetComponent<Renderer> ().material = materials [2];
				item.GetComponent<Renderer> ().material = materials [2];
				break;
			case "Marble Tower":
				wall.GetComponent<Renderer> ().material = materials [3];
				item.GetComponent<Renderer> ().material = materials [3];
				break;
			}
		}

		foreach (GameObject item in innerWalls) 
		{
			int makeWall = Random.Range (0, 2);
			if (makeWall == 1) 
			{
				GameObject innerWall = Instantiate (wall, item.transform.position, item.transform.rotation) as GameObject;
				innerWall.transform.parent = item.transform;
			} 
		}
			
		bool foundPath;
		Transform target = GameObject.FindGameObjectWithTag ("Teleporter").transform;
		foundPath = NavMesh.CalculatePath (transform.position, target.transform.position, NavMesh.AllAreas, path);
		Debug.Log (foundPath);
	}
}

Sure enough that was the issue made a custom script execution order with the other one going first and now it is fixed :slight_smile: