Why Again Arrays In ExecuteInEditMode() Gives NullReferenceException Errors??

Now I’m Facing Another Problem With Array.Length In ExecuteInEditMode().
I’m Trying To Make An Automatic Button To Set And Create Default Recommended Values, So When I Try To Change A Value From The Array(Class), It Gives Me NullReferenceException!
Here Is An Example Script I Made Which Doesn’t Work:
-C#:

using UnityEngine;
[ExecuteInEditMode()]
public class TEST : MonoBehaviour
{
	public bool create = false;
	public MyClass[] myType = new MyClass[0];
	[System.Serializable]
	public class MyClass
	{
		public float myVar = 0;
		public int _myVar = 0;
		public Transform m_myVar = null;
	}
	public void Update ()
	{
		if(create)
		{
			if(myType.Length == 0)myType = new MyClass[1];
			if(myType[0].myVar == 0)myType[0].myVar = 1;
			if(myType[0]._myVar == 0)myType[0]._myVar = 2;
			if(myType[0].m_myVar == null)myType[0].m_myVar = transform;
			create = false;
		}
	}
}

-JavaScript:

@script ExecuteInEditMode()
public var create : boolean = false;
public var myType : MyClass[] = new MyClass[0];
public class MyClass
{
	public var myVar : float = 0;
	public var _myVar : int = 0;
	public var m_myVar : Transform = null;
}
public function Update ()
{
	if(create)
	{
		if(myType.Length == 0)myType = new MyClass[1];
		if(myType[0].myVar == 0)myType[0].myVar = 1;
		if(myType[0]._myVar == 0)myType[0]._myVar = 2;
		if(myType[0].m_myVar == null)myType[0].m_myVar = transform;
		create = false;
	}
}

When I Edit The Script Or Recompile The Script It Will Work!!
Even If I Check The Length Or The Array It Self, It Doesn’t Work:
if(myType) Or if(MyType != null) Or if(myType.Length > 0) Or if(myType.Length != 0), None Of Them Work!
But In This Way It Works Fine, But I Have To Click The Button 2 Times To Make It Work:
if(myType[0]) Or if(myType[0] != null).
Thanks…

if(myType.Length == 0)myType = new MyClass[1];

You create a new array of MyClass that is 1 long. Without assigning any instances of MyClass to that array, it will just be filled will null.

if(myType[0].myVar == 0)myType[0].myVar = 1;

Here, you try to access the first element of myType, which is still null as you never assigned anything to it. You need to assign instances of classes to references for them to work.

Replace

if(myType.Length == 0)myType = new MyClass[1];

with

if (myType.Length == 0) myType = new MyClass[1] { new MyClass() };

Now you will create a new MyClass array that actually contains a live instance of MyClass, instead of null.