I have a Scriptable Object class that stores a list of Grid objects:
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class SpawnableGrids : ScriptableObject {
public List<LevelData.Grid> Grids;
void OnEnable() {
if (Grids == null) {
Grids = new List<LevelData.Grid>();
}
}
}
The LevelData.Grid class is as follows:
[Serializable]
// nested class to hold per grid information
public class Grid {
public int row;
public int column;
public Grid() {
row = column = 0;
}
public Grid(int row, int column) {
this.row = row;
this.column = column;
}
}
The class to create the asset looks like this:
using UnityEngine;
using System.Collections;
using UnityEditor;
public class CreateSpawnableGrids {
[MenuItem("Assets/Create/Greedy Assets/Spawnable Grids")]
public static void CreateAsset() {
SpawnableGrids grids = ScriptableObject.CreateInstance<SpawnableGrids>();
AssetDatabase.CreateAsset(grids, "Assets/NewSpawnableGrids.asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh ();
EditorUtility.FocusProjectWindow();
Selection.activeObject = grids;
}
}
Now I have an editor functionality that i use to fill the list of grids in the Scriptable object asset I create in the scene. Everything works fine and the list persists the data between edit and play mode. But when i quit unity and relaunch it, the data in the list is gone. I have read online posts and blogs and I am not sure why my data is not persisting between unity sessions. Please let me know if you all find something wrong with my code. I am new to Scriptable objects and unity in general.
Thanks in advance!