- Home /
Initializing variables with ExecuteInEditMode
I am trying to create a simple 2d grid. But I want it to be able to be edited in the scene without running the game. The problem is when I reach mNodeArray[ i, j ] = new_node; mNodeArray is not initialized. Does Awake() run before this is called. I have tried a few ways of doing it and have done it before but can't quite figure it out.
function CreateGrid( max_row : int, max_column : int )
{
var start_pos : Vector3 = new Vector3( 0, 0, 0 );
for( var i : int = 0; i < max_row; ++i )
{
for( var j : int = 0; j < max_column; ++j )
{
var new_node = Instantiate( mNodeObject );
//var node_data = new_node.GetComponent( Node );
var pos : Vector3 = Vector3( start_pos.x + mOffsetX * i , start_pos.y, start_pos.z );
// Set name and parent
new_node.transform.name = ( i.ToString() + "," + j.ToString() );
new_node.transform.parent = this.transform;
new_node.transform.position = pos;
mNodeArray[ i, j ] = new_node;
}
start_pos.y += mOffsetY;
}
}
function Update()
{
if( mIsCreateGrid )
{
DestroyGrid();
CreateGrid( mRow, mNumStrings );
mIsCreateGrid = false;
}
if( mIsDestroy )
{
DestroyGrid();
mIsDestroy = false;
}
}
Comment
Answer by TheEpigone · Aug 19, 2014 at 01:14 AM
For anyone who may stumble across this, it appears this is a bug in the editor.