Hi,
I’m struggling with Adding new Elements to a List that get’s serialized afterwards. Getting a bit confused here.
I have a SaveManager.cs storing a List-Class and the Functions for Saving and loading:
public class SaveManager : MonoBehaviour {
public static SaveManager control;
public class Error
{
public float X; public float Y; public float Z;
public Error( float newX, float newY, float newZ)
{
X = newX; Y = newY; Z = newZ;
}
}
public List<Error> ErrorList = new List<Error>();
[Serializable]
public class ListContainer
{
public List<Error> error;
}
void Awake()
{
if (control == null)
{
DontDestroyOnLoad(gameObject);
control = this;
}
else if (control != this)
{
Destroy(gameObject);
}
Load();
}
public void Save()
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/Data.dat");
ListContainer lc = new ListContainer();
lc.error = ErrorList;
bf.Serialize(file, lc.error);
file.Close();
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + "/Data.dat"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/Data.dat", FileMode.Open);
ErrorList = (List<Error>)bf.Deserialize(file);
file.Close();
Debug.Log("SaveFile Found and loadad");
} else
{
Debug.Log("No SaveFile Found. Started Clean");
}
}
}
Then i have a script for adding the entrys to the list. And there is the problem. I can’ using the Add-Function:
public List<SaveManager.Error> ErrorList = new List<SaveManager.Error>();
public void Create () {
float newX = ErrorX;
float newY = ErrorY;
float newZ = ErrorZ;
ErrorList.Add(new Error( newX, newY, newZ)); //<- Error: The type or namespace name `Error' could not be found.
}
Any idea why? I guess it’s super obvious -.-