GameObject List

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
joduffy
Posts: 2
Joined: Tue Feb 13, 2018 3:02 am

GameObject List

Post by joduffy »

Hi,

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;
}
Then I created a scriptableObject to store this data. That way any MonoBehaviour scripts written, can just reference this file to store and access the same information.
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;
.....
}
The data seems to be stored fine in the scriptableObject class.
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);
				}
So I am not saving the scriptableObject directly.
The error code I get when using ES2 is:
NullReferenceException: A null value was found where an object instance was required.
joduffy
Posts: 2
Joined: Tue Feb 13, 2018 3:02 am

Re: GameObject List

Post by joduffy »

So I was able to save the data to a file.
Turns out the fault was further up the code and not with ES2.

But the format I have in the text file is unreadable
$4ee756b5-fe96-41c0-b6c5-8baf2afa7d21\0\0\0\0anchor_0ÆkxºrlæDÆJ>\0\09¯ø◊Ω\0\0πUì~øÕÃÃ=ÕÃÃ=ÕÃÃ=Untagged\0\0\0\0anchor_0}•â=+2ZæÔú∂>\0\0\0\0\0\0\0\0\0\0\0Ä\0\0ÄøÕÃÃ=ÕÃÃ=ÕÃÃ=Untagged\0\0\0anchor_1fl´>*øæ°çÆ>\0\0\0\0\0\0\0\0\0\0\0Ä\0\0ÄøÕÃÃ=ÕÃÃ=ÕÃÃ=Untagged\0\0\0anchor_2±‹™Ω@MB=™ü?\0\0\0\0\0\0\0\0\0\0\0Ä\0\0ÄøÕÃÃ=ÕÃÃ=ÕÃÃ=Untagged\0\0\0anchor_3[r/æ¯ómæ˝ó?\0\0\0\0\0\0\0\0\0\0\0Ä\0\0ÄøÕÃÃ=ÕÃÃ=ÕÃÃ=Untagged
Should I convert all my transforms to strings and just use the WriteRaw?

Is it possible to just save a List<GameObject> directly.
I do have the ES2_GameObject but I seen the error saying saving GameObjects not supported.

My code before was:

Code: Select all

public List<GameObject> _anchorList;

				using(ES2Writer writer = ES2Writer.Create(textFilePath))
				{
					writer.Write(mapReferences.getAnchorList());
					writer.Save(false);
				}
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: GameObject List

Post by Joel »

Hi there,

You appear to have posted this in the Easy Save 3 forum rather than the Easy Save 2 one, so I have moved it.

Data is stored in binary format, so it is not readable in a text editor. If you wish to edit the file, you will need to do so with the ES2 methods, or using the File Editor (if the type of data is supported): http://docs.moodkie.com/easy-save-2/gui ... le-editor/

Alternatively you could convert the Transforms to strings and use WriteRaw/ReadRaw, but it would be your responsibility to parse that data.

With regards to the GameObject issue, did you remember to go to Assets > Easy Save 2 > Manage Types and press Refresh ES2Init after adding the ES2_GameObject to your scene?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked