ScriptableObject not saving to Asset properly
Greetings,
I'm trying to write my Scriptable Object to an Asset file, so I can load it again later. Problem is, when I close the Unity Engine Editor and open it again, all data inside the Asset file is gone.
How I save my Asset file:
AssetDatabase.CreateAsset(mapData, "Assets\" + map.name + ".asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
EditorUtility.FocusProjectWindow();
Selection.activeObject = mapData;
How my Asset File looks:
public class CompositMapData : ScriptableObject {
[SerializeField] private CompositTileData[] tiles;
public CompositTileData[] Tiles { get { return tiles; } }
public void SetData(CompositMapObject map) {
tiles = new CompositTileData[map.Tiles.Count];
for (int i=0; i < map.Tiles.Count; i++) {
tiles[i] = map.Tiles[i].ToData();
}
}
}
How the Data looks:
[System.Serializable]
public class CompositTileData {
private IntV3 position; // serializable class
private EdgeSet edgeSet; // scriptable object asset file
public IntV3 Position { get { return position; } }
public EdgeSet EdgeSet { get { return edgeSet; } }
public CompositTileData(CompositTileObject tile) {
position = tile.Position;
edgeSet = tile.EdgeSet;
}
}
Upon creation the Asset file seems to be just okay. I'm also able to get the Data back into the Scene again. But upon opening the Unity Engine Editor the next time, the Array inside the Asset file will be empty. Not null! but empty. please help me :(((
I also have the same problem with Data inside my MonoBehaviours. That is why I was hoping I could save them as Assets.
Your answer
Follow this Question
Related Questions
How can I get a sub asset? 1 Answer
AssetDatabase.LoadAssetAtPath Not finding assets 0 Answers
Load Assets into Unity without Asset Bundle at Runtime 0 Answers
SetDirty won't work on Nested List 1 Answer