Unity3D - how to use arrays with custom inspector code?
<p>I seem to be stuck in a catch 22 situation with the OnInspectorGUI method of Unity's UnityEditor class. I want to name array elements in the inspector for easy editing, currently I'm using, as per the documentation:</p>

<pre><code>public override void OnInspectorGUI()
{
   J_Character charScript = (J_Character)target;

   charScript.aBaseStats[0] = EditorGUILayout.FloatField("Base Health", charScript.aBaseStats[0]);

}
</code></pre>

<p>In my J_Character script I initialise the aBaseStats array like so:</p>

<pre><code>public float[] aBaseStats = new float[35];
</code></pre>

<p>The problem is that whenever I try to do anything in the editor (and thus OnInspectorGUI is called) I get an index out of range error pointing to the line </p>

<pre><code>charScript.aBaseStats[0] = EditorGUILayout.FloatField("Base Health", charScript.aBaseStats[0]);
</code></pre>

<p>I'm guessing this is because my array is initialized on game start while the editor code is running all the time while developing.</p>

<p>How can I get round this situation?</p>

<p>Many thanks.</p>