I have the following scriptable object:
[CreateAssetMenu(fileName = "Assets/Gladio Games/Resources/Levels/LEVLE_TMP", menuName = "Utils/Crossword/Generate Empty Level", order = 100)]
public class Level : ScriptableObject
{
public char[,] Table { get; protected set; }
public List<Crossword> Crosswords { get; protected set; }
protected static char EMPTY_CHAR = '\0';
public Crossword GetCrosswordAtIndex(int x, int y, Direction direction)
{
//Ottieni la prima e l'unica parola che si trova sotto quell'indice
return Crosswords.First(crossword => crossword.Direction == direction && crossword.GetCrosswordIndexes().Contains(new Vector2(x, y)));
}
}
This is the code that I use to save the Scriptable Object
private static void Save(Level level, string path)
{
EditorUtility.SetDirty(level);
AssetDatabase.CreateAsset(level, path + ".asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
The object is created successfully through an editor script and it has all the data saved, but if I close and reopen the Editor, and try to load the fields are null. The script to save and load the scriptable object are used within the scene
What I'm doing wrong?
Checkout the Script serialization rules
In particular in your case
So both your properties are not serialized (= saved) at all.
As a solution
For
Crosswords
Make sure that the type
Crossword
itself is[Serializable]
Use a field instead
For
Table
there are multiple ways.I would probably simply use a wrapper class like e.g.
And then rather have e.g.