- Home /
Question by
Le-Capitaine · Sep 04, 2014 at 01:09 PM ·
c#nullreferenceexceptionlistsnewcustom class
Does a new instance of a custom class return null?
List<ObjectPool> bulletPools;
List<ObjectPool> AIPools;
void MakePools () {
for (int i = 0; i < game.bulletPools; i++) {
bulletPools.Add (new ObjectPool()); //NRE here
}
for (int i = 0; i < game.AIPools; i++) {
AIPools.Add (new ObjectPool());
}
}
The lists aren't public and game
is tested and properly initialised; its pool values are both 100. The script uses System.Collections.Generic
. Built-in arrays have been tried to no more success. I tried initialising my new ObjectPool
into a variable on a separate line and adding that; no dice. I really don't have the slightest idea just what it is that I'm doing wrong.
Comment
Best Answer
Answer by superdudeman · Sep 04, 2014 at 01:22 PM
Try this when declaring the variables.
List<ObjectPool> bulletPools = new List<ObjectPool>();
List<ObjectPool> AIPools = new List<ObjectPool>();
Yup, I'm just that much of a bloody idiot, am I. ._.
Thanks and thanks again.
Answer by supericecream · Sep 04, 2014 at 01:25 PM
You probably didn't initialize the lists like such:
bulletPools = new List();
AIPools = new List();
I'm I wrong in this?