Access System.Serializable class from script?

I’m trying to declare by script the following struct:

[System.Serializable]
public class GoogleMapMarker
{
	public enum GoogleMapMarkerSize
	{
		Tiny,
		Small,
		Mid
	}
	public GoogleMapMarkerSize size;
	public GoogleMapColor color;
	public string label;
	public GoogleMapLocation[] locations;
	
}

using

		GoogleMapMarker[] markers = new GoogleMapMarker[2];
		
		markers[0].color = GoogleMapColor.red;
		markers[1].color = GoogleMapColor.blue;

But, I always end up with “NullReferenceException: Object reference not set to an instance of an object” on the line where markers[0] starts…

I had thought I defined it to be an array of size 2, so I am not sure why it is saying null object? Is System.Serializable not accessible from script? Is there another way to do this?

Declaring an array of objects doesn’t actually make any objects. It’s a container for objects. You still have to initialize each one with markers[n] = new GoogleMapMarker();