Changed data through EditorWindow isn't persistent.

Hello,

I am using a custom script to show an EditorWindow which will display the data of one script attached to GameObjects.

using UnityEngine;
using UnityEditor;
using System.Collections;

public class ShowLevelData : EditorWindow {

	private GameObject go;
	private Level level;
	// Add menu named "My Window" to the Window menu
	[MenuItem ("Window/Show Level Data")]
	static void Init () {
		// Get existing open window or if none, make a new one:
		ShowLevelData window = (ShowLevelData)EditorWindow.GetWindow (typeof (ShowLevelData));
		window.position = new Rect(150,150,113,149);
		window.minSize = new Vector2(113,149);
		window.ShowPopup();
	}

	void OnSelectionChange(){
		go = Selection.activeGameObject;
		level = go.GetComponent<Level>();
		Repaint();
	}

	void OnGUI () {
		if(level){
			level.level = EditorGUILayout.IntField("Level Number",level.level);
			EditorGUILayout.BeginVertical ();
			EditorGUILayout.LabelField("1  2  3  4  5  6  7");
			for(int i = 0;i<7;i++)
			{
				EditorGUILayout.BeginHorizontal();
				for(int j=0;j<7;j++)
				{
					level.levelData[i,j] = EditorGUILayout.Toggle (level.levelData[i,j]);
				}
				EditorGUILayout.LabelField(""+i);
				EditorGUILayout.EndHorizontal();
			}
			EditorGUILayout.EndVertical();
		}
	}
}

This script shows a two-dimensional array in my other script ‘Level’ attached to a GameObject in my scene. There are multiple objects with this script attached to them. So whenever I select them and have this window open, I can see the two dimensional array.48224-capture.png

The changes I make to this is present as far as I don’t close Unity. Once I close Unity and restart, its gone. Same is for any other property of the script I change,(for example, the level number).

I can see it updated in the inspector once I change it, but even if I save the scene, the changes don’t stay if I close Unity.

Does any one know how to fix this?

Well, your “levelData” array seems to be a multidimensional array. However the Unity serializer doesn’t support those. If you want this data to be saved, use structures / types which are supported or save it on your own into a file.