Unity 5.0.0: Error: Code (csharp): NullReferenceException: Object reference not set to an instance of an object Unit.Start () (at Assets/Resources/Scripts/Unit.cs:28) Code: Code (csharp): using UnityEngine; using System.Collections; using System.Collections.Generic; public class Unit : MonoBehaviour { public static List<GameObject> UnitObjectX = new List<GameObject>(); public Texture2D PMenuIcon; public Texture2D PMenuIconRo; public static Texture2D MenuIcon; public static Texture2D MenuIconRo; public GameObject GUIGhostObjectX; public static GameObject ObjectX; public Material GhostMat; public static Material GhostMatStat; void Start () { GhostMatStat = GhostMat; ObjectX = GUIGhostObjectX; UnitObjectX.Add (ObjectX); MenuIcon = PMenuIcon; MenuIconRo = PMenuIconRo; Menu.UnitIconTextures.Add (PMenuIcon); Menu.UnitIconTexturesRo.Add (PMenuIconRo); GUIGhostObjectX.AddComponent<Renderer>().material = GhostMatStat; } }
You can see in the error that it points to Unit.cs line 28. If you look down to line 28 you can see Menu.UnitIconTexturesRo.Add(); Menu.UnitIconTexuresRo is null, and that's your problem.
Doesn't change much. In that case Menu.UnitIconTextures is null. It is likely a static variable that is not initialized properly.
Looks like GhostMatStat is null. Make sure the material is set in your inspector since you're not defining it locally. Also, errors like these can be solved 99.9% of the time with a little time spent double checking. The compiler usually knows best. If it says there's a null reference, then that means you're trying to reference and object that is null. So go to the line that it's pointing at and start checking each object reference until you find which is null. For line 29 you'd want to check GUIGhostObjectX and GhostMatStat. It's also really good to explain in your initial post what you've tried to do to solve the problem.