I have an object with a multi-dimensional array of game objects that is initialized and filled in a function called from a custom inspector during edit mode. As soon as I press play the object is destroyed and rebuilt, which makes the array uninitialized/empty again.
I call 'DontDestroyOnLoad(this.gameObject)' in the object's awake function, but this doesn't seem to be doing anything. How can I preserve this array between edit and play modes? Thanks.
Edit: Here is the initialization for the array I'm trying to keep around. The 'fillArray()' function is called on a button press from my custom inspector. I noticed no difference after adding [System.Serializable] and [SerializeField]
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class ArrayTest : MonoBehaviour
{
//Array size variables
int
iLength,
iWidth,
iHeight;
//A 3D array of game objects to be filled
[SerializeField]
GameObject[,,] goPrefabs;
//Prefab of game object to put in 3D array
public GameObject goPrefab;
public void fillArray()
{
iLength = (int)(transform.localScale.x);
iWidth = (int)(transform.localScale.z);
iHeight = (int)(transform.localScale.y);
goPrefabs = new GameObject[iLength, iHeight, iWidth];
//Fill the array with game objects
for(int i = 0; i < iLength; i++)
{
for(int j = 0; j < iHeight; j++)
{
for(int k = 0; k < iWidth; k++)
{
GameObject goCurrentObject = Instantiate(goPrefab) as GameObject;
goPrefabs[i, j, k] = goCurrentObject;
}
}
}
}