Problem to save a list

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
nicolas
Posts: 2
Joined: Mon Mar 04, 2013 7:44 pm

Problem to save a list

Post by nicolas »

Hello Joel

I have tried the list given in Easy Save 2 examples and it work well

But I have created a list using the following code

Code: Select all

using UnityEngine;
using Serialization;
using System.Collections.Generic;
using System.Collections;

public class TestPositionListsES2 : MonoBehaviour
{


    public List<pos> positions = new List<pos>();
    List<pos> myOtherList = new List<pos>();

    public class pos
    {
        private int _frame = Time.frameCount;
        private float _time = Time.time;
        public Vector3 position;
        public Quaternion rotation;
        public Vector3 velocity;
        public Vector3 angularVelocity;
    }


    // Use this for initialization
    void Start()
    {
    }

    // Update is called once per frame
    void FixedUpdate() {

        positions.Add(new pos { position = rigidbody.position, velocity = rigidbody.velocity, 
        angularVelocity = rigidbody.angularVelocity, rotation = rigidbody.rotation });

        if (Input.GetKeyDown(KeyCode.Z))
        {
            ES2.Save(positions, "C:/MyFile.txt?tag=positions");
        }

        if (Input.GetKeyDown(KeyCode.A))
             myOtherList = ES2.LoadList<pos>("C:/myFile.txt?tag=myList");
    }

}
It does not work and I have the following message

ES2TypeNotSupportedException: Easy Save does not support saving this type. If you are trying to load a collection such as a Dictionary or Array, use the collection classes (for example, LoadDictionary<>() or LoadArray<>()).
MoodkieWriter.Write (System.Object param)
MoodkieWriter.Write[pos] (System.Collections.Generic.List`1 param)
MoodkieSave.Save[pos] (System.Collections.Generic.List`1 param, .ES2Settings settings)
ES2.Save[pos] (System.Collections.Generic.List`1 param, System.String identifier)
TestPositionListsES2.FixedUpdate () (at Assets/Utilities/Scripts/TestPositionListsES2.cs:37)
So my question is to know what I am doing wrong and what I can do to solve that problem.

Thanks in advance

Nicolas

User avatar
Joel
Moodkie Staff
Posts: 3778
Joined: Wed Nov 07, 2012 10:32 pm

Re: Problem to save a list

Post by Joel »

Hi Nicolas,

You may only save types which are in the Easy Save Supported Types list. You are trying to save a list containing your own 'pos' class.

For more information on how you might go about saving your own custom classes, please see this tutorial.

All the best,
Joel

nicolas
Posts: 2
Joined: Mon Mar 04, 2013 7:44 pm

Re: Problem to save a list

Post by nicolas »

Hi Joel
I missed that tutorial, thanks.
Nicolas

lebidl
Posts: 1
Joined: Sun Apr 21, 2013 12:36 pm

Re: Problem to save a list

Post by lebidl »

I am a beginner in unity.
to save my inventory I use this code.
not optimized but it works

Code: Select all

//InventoryItem
string name //item name
int invAmount //item amount
float Value // item value
int tbPos //position in toolbar

//exemple
public List<string> savelist;

public void Save ()
	{
	
		for (int i = 0; i < inventory.Count; i++)
		{
				string itemInfo = inventory [i].name + "/" + inventory [i].invAmount + "/" + inventory [i].Value + "/" + inventory [i].tbPos;
				savelist.Add (itemInfo);
		}
		ES2.Save (savelist, PlayerName + ".txt?tag=savelist");	
   	}
	
public void Load ()
   {
      if (!ES2.Exists (PlayerName + ".txt"))
			return;	
	 savelist = ES2.LoadList<string> (PlayerName + ".txt?tag=savelist");
	splitlist ();

}
void splitlist ()
	{
	
	for (int i = 0; i < this. savelist.Count; i++) {
			string[] Info = savelist [i].Split ("/" [0]);
			string i1 = Info [0]; //name
			int i2 = int.Parse (Info [1]); //invAmount
			float i3 = float.Parse (Info [2]); //Value
			int i4 = int.Parse (Info [3]); //position in toolbar
			InventoryItem it = inventoryControl.FindItem (i1);
			it.invAmount = i2;
			it.Value = i3;
			addItemInv(it);
		}	
	}

Locked