In Unity (C#), why am I getting a NullReferenceException and how do I fix it? [duplicate]

Explanation In C# generally, this is caused by referencing a field that hasn’t been initialized. For example, if you have a field public List<GameObject> items and you later call items.Add(foo) without first doing items = new List<GameObject>(), then you are trying to add an item to a list that doesn’t exist. However, in Unity specifically, … Read more