Data tree crash to be expected?

Unity really doesn’t like this code:

var myTree : treeElement;

class treeElement {
	var nextElement : treeElement[];
	var textString : String;
}

Unity crashes and I have to go delete the compiled script to get Unity to launch again.

I realize that the tree could potentially go on forever… but that’s the point, and since the number of elements in each array will default to zero… it doesn’t go on forever.

Should I submit this as a bug, or is this to be expected? If it is to be expected is their an alternative for making a tree?

Obviously I could use the other type of array, and since each elements type isn’t stated there’s no chance the array could be perceived to go on forever. The problem with this however is that it makes the code much less reusable, or at least harder to reuse.

Uninitialized this should crash so → bugreport

But once it is initialized, myTree will potentially resolve deep → gui can be initely large → boom

the property inspector also does not allow you to apply nested structures to a property so you might not really want to use that as it fights the use of the property inspector as you will no longer be able to just apply things .

var myTree : treeElement; 

class treeElement { 
   var nextElement : treeElement[]; 
   var textString : String; 
}

doesn’t the treeElement array within the class cause an infinite declaration of treeElements?

It shouldn’t. All the uninitialized array does is act as a placeholder. The next level of treeElement is not initialized until you declare a nextElement*=new treeElement(); in which case it just creates another placeholder.*

Correct me if I’m wrong, but if you declare an Array like this, doesn’t it fix the size of the array to whatever you have it declared as in the inspector?

Yep, they’re built in arrays, and they are extremely fast compared to resizable arrays. Use them if you don’t need to change the size of an array.

This still seem to be an issue.

The work around that i’ve found is to use a MonoBehavior instead:

treeElement.py

var nextElement : treeElement[]; 
var textString : String;

useTree.py

var myTree : treeElement;

This approach means that you have to add the component to an object so that you can use assign it. Ugh! Hope this gets fixed.