I've got a GameObject that is being instantiated:
var face = Instantiate(waveConfigs[waveNumber].getFacePrefab(), waypoint.position, Quaternion.identity, FindObjectOfType<Canvas>().transform);
Debug.Log(face, this);
faces.Add(face);
faces
is declared above like this:
List<GameObject> faces;
The object gets instantiated, the DebugLog is follows:
Smile(Clone) (UnityEngine.GameObject)
UnityEngine.Debug:Log(Object)
FaceSpawner:SpawnFaces(Int32) (at Assets/Scripts/FaceSpawner.cs:30)
FaceSpawner:Start() (at Assets/Scripts/FaceSpawner.cs:16)
(Which is the Debug.Log(face, this);)
And then straight after that, when I call faces.Add()
:
NullReferenceException: Object reference not set to an instance of an object
FaceSpawner.SpawnFaces (System.Int32 waveNumber) (at Assets/Scripts/FaceSpawner.cs:31)
FaceSpawner.Start () (at Assets/Scripts/FaceSpawner.cs:16)
I dont get it, I've literally just assigned this variable, its worked, it appears on the canvas, I can log it out the debuglog, and then when I try and add it to a List I get a NullReference. What is going on here?