Hi. I created a method to save objects that inherit from ScriptableObject. It’s creating the new asset just fine but its not saving the inherited data when the asset is created. I know I’m just not understanding something crucial here.
// Serializable attribute is not required, as ScriptableObject is already flagged.
public class SwipeSession : ScriptableObject
{
// name is a field of UnityEngine.Object. You should probably flag it "new" or ignore it.
// UnityEngine.Object name field also is special as it automatically take the file's name, but won't change the file's name if modified.
//public string name = "";
public List<Vector3[]> levels = new List<Vector3[]>();
}
Beside that, you’re not showing us how you create the asset (ScriptableObject.CreateInstance) and how you fill its data because saving it.
private void saveAndWriteSession()
{
saveLevel();
CustomAssetUtility.CreateAssetAtPath("SwipeSessions",session.sessionName,session);
}
private void saveLevel()
{
Vector3[] lvlData = new Vector3[record.Count];
for(int i = 0; i < lvlData.Length;i++)
lvlData[i] = findTriangleCenter(record.Pop());
session.levels.Add(lvlData);
clear();
}
I’m using this to test it
public class CustomAssetTester : MonoBehaviour {
public SwipeSession session;
// Use this for initialization
void Start ()
{
Debug.Log(session.sessionName);
Debug.Log("Session Levels:" + session.levels.Count);
}
}
Session name is being outputted correctly but Session levels is giving me zero. Not sure how one can work but not the other.
But I found the problem. This way of saving data will ONLY save the data if you can see it through unity’s inspector. I tried saving a single Vector[ ] and that worked but the moment i turned it into a Vector[ ][ ] it broke.