I tried to save a list of gameobjects but had no luck.
So then I tried a different approach that would give more flexibility to the project.
I started by creating a simple class to store data in:
Code: Select all
public class ObjectInfo
{
public int objId;
public string objName;
public Transform objTransform;
}
Which also makes it easier to debug on the project side of things.
Code: Select all
public class ObjectInfoReferences : ScriptableObject
{
public string _mapID;
//public List<GameObject> _anchorList;
//public List<GameObject> _planeList;
public List<ObjectInfo> _anchorList;
public List<ObjectInfo> _planeList;
.....
}
Its when I go to save the data. I do separate out the data. Similar to this post:
http://www.moodkie.com/forum/viewtopic. ... list#p3614
Code: Select all
string textFilePath = Path.Combine(Application.persistentDataPath, mapReferences._mapID + ".txt");
using(ES2Writer writer = ES2Writer.Create(textFilePath))
{
//writer.Write(mapReferences.getAnchorList().Count + mapReferences.getPlaneList().Count);
Debug.Log("About to write map id");
writer.Write(mapReferences.GetMapID());
Debug.Log("About to write anchors");
foreach(var uniqueID in mapReferences.getAnchorList())
{
writer.Write(uniqueID.objId);
writer.Write(uniqueID.objName);
writer.Write(uniqueID.objTransform);
}
Debug.Log("About write save plane list");
foreach(var uniqueID in mapReferences.getPlaneList())
{
writer.Write(uniqueID.objId);
writer.Write(uniqueID.objName);
writer.Write(uniqueID.objTransform);
}
Debug.Log("about to save file");
writer.Save(false);
}
The error code I get when using ES2 is:
NullReferenceException: A null value was found where an object instance was required.