- Home /
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
}
Are there any errors? Could you post the lines of code were wayPoints
is declared/initialised?
Answer by salex100m · Nov 07, 2013 at 12:42 PM
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.
Answer by _MGB_ · Nov 07, 2013 at 01:46 PM
Did you create a new list before using it? i.e.
wayPoints = new List<WayPoint>();
Yes, I forget to do this sometimes... ;)
yeah everything works fine, except the list wont add anything. im pretty sure that it is adding now, just that later in the code it must be clearing the queue in the same update.
so my initial question is solved.
Your answer
