- Home /
Get Count of a List inside a List / Class
Hi,
I am trying to check the count of a list which is inside another list, but can't seem to quite get it.
Here is an example:
var waypointPositionsList = List.<WayPointsClass>();
class WayPointsClass
{
var Id : String;
var wayPointPosition : List.<Vector3>;
}
if(waypointPositionsList[0].wayPointPosition.Count > 2)
{
//Do Stuff
}
Gives me: NullReferenceException: Object reference not set to an instance of an object listOfLists.PlotWayPoint ()
Any ideas?
Thanks!
Comment
It looks like the item at waypointPositionsList[0] is null.
This should test the theory:
WayPointsClass item = waypointPositionsList[0];
if(!item) {
Debug.Log("null item at waypointPositionsList[0]");
}
Best Answer
Answer by Vonni · Dec 31, 2013 at 06:16 AM
Thats because wayPointPosition is not set, its null
You need a constructor for it
Yep, that was it Vonni! I had tried a constructor before but was way off in my initial implementation. Gave it a go again after you confirmed it.
Thanks :)
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Voting System Using List (C#) 1 Answer