This should be obvious - List issue

Hello All,
i am looking for something obvious that i am missing…

I have a list that is populated in the Start routine using the code below. It’s just a list of waypoints.
if i break inside the start routine, the list is populated.
once start completes, however, the list is empty generating an argument out of range error.

any thoughts?

public List CircuitPoints;

void Start ()
{
List CircuitPoints = new List();

CircuitPoints.Add(GameObject.Find(“StartPtLWL”).transform.position);
CircuitPoints.Add(GameObject.Find(“leftStep1_lw”).transform.position);
CircuitPoints.Add(GameObject.Find(“leftStep2_lw”).transform.position);
CircuitPoints.Add(GameObject.Find(“Step3_lw”).transform.position);
CircuitPoints.Add(GameObject.Find(“WaterEntry”).transform.position);
}

You’re defining a new list in the Start() scope. Any time you define a variable in the outer scope you no longer need to specify the type on the inner scope when you want to reference it. When you do specify the type it thinks you’re defining a new variable and leads to ambiguity/errors with duplicate names.

old/new.

List<Vector3> CircuitPoints = new List<Vector3>();
CircuitPoints = new List<Vector3>();

Also, use UBB code tags when posting code.

1 Like

perfect! thanks for the quick response…