- Home /
Can anyone help with this serialization script (missing the class attribute 'ExtensionOfNativeClass'!)
I was creating big game but I can't solve this problem:
I don't whats wrong with this script, name is "SaveLoadManager", can anyone help?
 public static class SaveLoadManager
 {
     public static string SaveName;
 
     public static void SavePlayer (Player player)
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream stream = new FileStream(Application.persistentDataPath + SaveName + ".fun", FileMode.Create);
 
         PlayerData data = new PlayerData(player);
 
         bf.Serialize(stream, data);
         stream.Close();
     }
 
     public static PlayerData LoadPlayer()
     {
         if (File.Exists(Application.persistentDataPath + SaveName + ".fun"));
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream stream = new FileStream(Application.persistentDataPath + SaveName + ".fun", FileMode.Open);
 
             PlayerData data = bf.Deserialize(stream) as PlayerData;
             stream.Close();
             return data;
         }
     }
 }
 
 [Serializable]
 public class PlayerData
 {
     public int health;
     public float hunger;
     public float thirst;
     public float[] position;
     public GameObject PlayerGameObject;
     
     public PlayerData(Player player)
     {
         health = player.health;
         thirst = player.thirst;
         hunger = player.hunger;
         position = new float[3];
         position[0] = PlayerGameObject.transform.position.x;
         position[1] = PlayerGameObject.transform.position.y;
         position[2] = PlayerGameObject.transform.position.z;
          
     }
 }
My only problem is this error: 
Please help me!
Hi, I think serializing a GameObject reference (or any Unity object) like this is not possible. Does it work if you remove the ref to a GameObject? Search for Unity save systems, they usually work with some kind of unique ID for Unity's objects as they live half in C# managed environment and half in C++ native environment and must be (de)serialized by Unity (loading scenes, resources, asset bundle etc...).
Answer by CodesCove · Aug 05, 2020 at 07:40 PM
Did you perhaps have same named class earlier that was inherited from Monobehaviour or something.. ? Try renaming the SaveLoadManager class and check if that helps.
sorry I renamed it to SaveLoadScript and it not solved this problem
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                