I get an error whenever I try and use the saveTerrainDatabase() method in my code below.
SerializationException: Type UnityEngine.MonoBehaviour in assembly UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null is not marked as serializable.
I’ve read from another question posted on unity answers that classes inheriting from monobehavior can be serialized (which I have done).
using UnityEngine;
using System.Collections;
using System.Xml;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
[System.Serializable]
public class terrainManager : MonoBehaviour {
public chunkManager[] chunks = new chunkManager[100];
private fileManager fm = new fileManager();
private bool isDataEncrypted = false;
public void Awake()
{
fm.initialize();
fm.createDirectory("Database"); //creates a file directory if one does not exist
if(fm.checkFile("Database/Terrain.dat") == true) //if file exists, use it
{
Debug.Log("File found");
loadTerrainDatabase();
}
else //else create a new file if there isn't one
{
Debug.Log("Creating new file");
fm.createFile("Database","Terrain","dat","empty terrain file",isDataEncrypted);
}
}
public void loadTerrainDatabase()
{
}
public void saveTerrainDatabase()
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms,this);
fm.updateFile("Database","Terrain","dat",Convert.ToBase64String(ms.GetBuffer()),isDataEncrypted, false);
}
The error exception highlights line 41 whenever I double click the error in the console.