using own type gives nul reference

Hi there guys

I’m a bit stumped why the following is giving me a null reference exception. I have my iwn struct that i use to save some info and put that in a List called pageList and of type lessonPage. Here is the code that populate the properties and Lists in my type:

if (GUI.Button(new Rect(camera.pixelRect.xMin + 330, yPos - camera.pixelHeight + 210, 100, 40), "ADD PAGE"))
        {
            lessonPage lp = new lessonPage();
            lp.pageName = PageName;
            lp.totalTime = createNewTimePoint.totalTime;

            foreach (GameObject tp in GameObject.FindGameObjectsWithTag("timePoint"))
            {
                lp.clockName.Add(tp.name);
                lp.clockPosition.Add(tp.transform.position);
                lp.clockTime.Add(tp.GetComponent<timePointBehaviour>().timeValue);
                lp.clockText.Add(tp.GetComponent<timePointBehaviour>().thisPointText);
            }
        }

The lp.PageName and lp.totalTime seems to work fine, but the first line in hte loop gives the error and when I comment that out, the next etc. I dont get it…

Your structure in this case is immutable, replace the whole object, or access them directly rather then through a for each loop.

Thanks Siegeon

I’m not sure I follow, but also, when I take the loop completely away it also gives the same error. Another thing I don’t understand is why does the “lp.pageName = PageName;” line and the one after that works then?

Thanks

The problem was that I did not create new instances of the lists in my type. Solution was to declare it as new object.