- Home /
List of ScriptableObjects lost on project reload
I'm trying to create a list of scriptableobjects, Grid, but for some reason I can't figure out, the instances of the Grid get reset when I restart the project. The actual list will have the same amount of objects in it, but they are all null.
How do I make sure the Grid objects are saved.
The instances don't get deleted when I switch between editor and play mode. It's just on project reload.
Answer by Ymrasu · Feb 26, 2019 at 03:02 PM
To me, the idea behind ScriptableObjects is so you can have data as assests and work with them within the editor. With that said, if you have several ScriptableObject assests that you created that you want in a list, I would make a public array of them, drag and drop them onto the array in the editor, then convert the array into a list on start if wanted.
public Grid[] gridArray;
List<Grid> gridIslands;
void Start() {
gridIslands = new List<Grid>(gridArray);
}
I agree with your idea about using ScriptableObjects as data, that's what I'm trying to do here too. However, the grid scriptableobject isn't actually an asset. The data class which holds the gridIslands list is a scriptable object asset.
I don't think the Grid class should be a scriptableobject if you are not creating assets of it. I think they need to be explicitly saved as assets.
The data class can still use the array approach. You can just Serialize the grid class (if it is just holding basic data). Then you can add them to the data class manually.
[System.Serializable]
public class Grid
{
public string dataPoint1;
public int dataPoint2;
public float dataPoint3;
}
Your answer
Follow this Question
Related Questions
Scriptable Object's Data Gets Lost After Re-opening Unity!!! 1 Answer
BinaryFormatter - saving and loading a list containing sprites. 0 Answers
ScriptableObject loses data after Reload 1 Answer
Unable to serialize my list in a Unity Custom Editor script. 1 Answer
Difference between assigning a value in inspector and with a custom editor script 1 Answer