problem polulating arrays with childs collider sizes


I’m trying to get the sizes of box colliders of a bunch of objects that i have in an array, so that i can calculate the objects rough areas.
Currently I’m trying to fill a bunch of arrays with the info i need from the objects on start so that i can calculate the lift for each aerofoil attached to an object and apply forces to the parent rigid body.

	public GameObject [] aerofoilSurfaces;
	private BoxCollider [] collider;

		//get aerofoils surface areas
		for(int i = 0; i < aerofoilSurfaces.Length; i++)
			collider _= aerofoilSurfaces*.GetComponent<BoxCollider>();*_

surfaceXArea = collider_.size.y * collider*.size.z;
surfaceYArea = collider.size.x * collider.size.z;
surfaceZArea = collider.size.x * collider.size.y;
I’m not that confident with arrays yet and the code i have created doesn’t seem to do anything….which is annoying. hoping someone can shed some light.
i do get the error:
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)*

finSurfaceScript.Start () (at Assets/finSurfaceScript.cs:38)
thanks in advance for your time!_

I’m not sure if this is all the code, but the code I see here is not creating any entries in the array. That is, it is creating a reference to an an array, but it is not initializing the array. Typically you would do something like this:

private BoxCollider[] collider = new BoxCollider [10];

This would create an array with ten entries. Or if the size of ‘collider’ needs to match the number of entries in ‘aerofoilSurfaces’ then you would declare the array as you’ve done here, then later in the code you would do:

collider = new BoxCollider[aerofoilSurfaces.Length];

Note if you don’t know the number of entries you need in your array, then consider using some other .NET colliection type…A generic List is the most common one used in answering questions on UA where the number of entries is not know up front. More information on collection types can be found here: