- Home /
Saving a variable from an editor script into something like a gamemanager script?
So I made this grid editor script where I pull in an empty game object from the scene and in the grid editor script it creates a grid using a couple for loops and instantiating the cubes in scene. In the grid editor script it also creates a grid array where I store all the game objects into a 2D array named gridArray. I can't reference that gridArray because it's an editor script. I was wondering if there was a way to save the grid array to a game manager script that has a public 2d array that I can call gridFloor or something in order to have a reference to it from other scripts.
for Example my Game Manager Script has this variable to make a reference to it from other scripts:
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour
{
public GameObject[,] GridFloor;
}
My GridEditor Script:
using UnityEditor;
using UnityEngine;
public class GridEditor : EditorWindow
{
public GameObject[,] gridArray;
public GameManager gm;
[MenuItem("Window/Grid Editor")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(GridEditor));
}
void OnGUI()
{
GUILayout.Label("Grid Settings", EditorStyles.boldLabel);
gm = (GameManager)EditorGUILayout.ObjectField("GameManager", gm, typeof(GameManager), true);
}
void GenerateGrid()
{
//after the grid is generated and all of the gridArray values have been stored
//is there a way to do something like this:
gm.GridFloor = gridArray;
//And then have it actually save the variables into the gm array
}
}
so with debug statements, in the grid editor script the gm.GridFloor.length was actually set to what gridArray's length was, which let me know that it worked. BUT when I made a debug statement in the awake function of the game manager script it gave me an error saying that the gridFloor array has not been set to an instance of an object. MEANING that the gridFloor was NOT saved in the editor script. Is there a way to save the variables from the editor script?