- Home /
Null Reference Exception because of a List
Okay, I have various lists that need to be linked together after they're created. So, I have 2 global lists:
public static List<GameObject> objectDefinitions;
public static List<WeaponSet> weaponSets;
However, when I call a function from the same class:
public void AddGameObject(GameObject go)
{
objectDefinitions.Add(go);
} // AddGameObject()
I get a null reference exception. I know that the game object is initialized as a game object. For some reason, the objectDefinitions list has a null reference. When the objectDefinitions list is not static it also works fine. Of course I don't want to use a non-static because of needing to link the various object. Using a static list makes that much nicer.
Thoughts?
Answer by PAEvenson · Jun 02, 2013 at 03:08 AM
Yes, your lists are null...(cant remember if you can set static objects...may need to do this in Awake)
public static List<GameObject> objectDefinitions = new List<GameObject>();
public static List<WeaponSet> weaponSets = new List<WeaponSet>(); ;
Well I feel stupid.
Now to figure out why linking these together isn't working, but that's for a different thread.
Your answer
Follow this Question
Related Questions
Null reference exception: Object reference not set to an instance of an object 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
A node in a childnode? 1 Answer