List.Add(waypoints) broken? What am I missing?

Folks, I need some help! I can’t get this stupid piece of code to work, even though I’m sure I had it working before…

All I’m trying to do is add my WayPoint object to my List of Waypoints… But for some reason, when I add this line of code “wayPoints.Add(temp);”, the whole thing fails. If I comment out the line, everything else works (except my waypoint clones are all sitting around without a list to connect them)!

			if (mainCamPlane.Raycast(ray, out hitdist)) {
				destinationPoint = ray.GetPoint(hitdist);
				destinationPoint.y = 0;				
				WayPoint temp = (WayPoint) Instantiate(waypoint_orig, destinationPoint,Quaternion.identity);
				wpAddToList = temp; //publicly exposed variable for testing...
                wayPoints.Add(temp); //the offending line


Thanks for the reply.

No errors or anything like that. When I segregated this piece of code to post here, looks like it works independently.

So… There must be something later on in my code that is clearing my queue in the same update. I’ll have to add the rest of the script back into the segregated piece and see what’s is doing it.

Did you create a new list before using it? i.e.

wayPoints = new List<WayPoint>();

Yes, I forget to do this sometimes… :wink: