- Home /
Help with Binary Save system
Hi, thanks for your time this error message alone is a big one. the game has been on the backburner with everything going on I have time to work on it. when I first made this save system it worked just fine but after I move to the latest vers of unity I get this error on save. for the mod sorry about reposting I didn't know it still posted when I got a bad get way thanks mods.
Error"
SerializationException: Type 'UnityEngine.ScriptableObject' in Assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers (System.RuntimeType type) (at :0) System.Runtime.Serialization.FormatterServices+<>c_DisplayClass9_0.b0 (System.Runtime.Serialization.MemberHolder ) (at :0) System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) (at :0) System.Runtime.Serialization.FormatterServices.GetSerializableMembers (System.Type type, System.Runtime.Serialization.StreamingContext context) (at :0) System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo () (at :0) System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize (System.Type objectType, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.SerializationBinder binder) (at :0) System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize (System.Type objectType, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.SerializationBinder binder) (at :0) System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo memberObjectInfo) (at :0) System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo typeNameInfo) (at :0) System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize (System.Object graph, System.Runtime.Remoting.Messaging.Header[] inHeaders, System.Runtime.Serialization.Formatters.Binary.__BinaryWriter serWriter, System.Boolean fCheck) (at :0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers, System.Boolean fCheck) (at :0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers) (at :0) System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) (at :0) SaveSystem.Save () (at Assets/arena/Code/All_Mangers/SaveSystem.cs:146) GameControllerEditor.OnInspectorGUI () (at Assets/arena/Code/Editor/GameControllerEditor.cs:22) UnityEditor.UIElements.InspectorElement+<>c_DisplayClass58_0.b_0 () (at :0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
using UnityEngine;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections.Generic;
public void Save()
{
hasSave = false;
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.data");
PlayerData data = new PlayerData();
data.playerLevel = playerLevel;
data.xp = xp;
data.xpToNextLevel = xpToNextLevel;
data.skillPoints = skillPoints;
hasGame = true;
data.hasGame = hasGame;
data.gold = gold;
data.drawSpeed = drawSpeed;
data.drawSpeedNumber = drawSpeedN;
data.AddHealth = AddHealth;
data.AddHealthN = AddHealthN;
data.drawSpeedDamage = drawSpeedDamage;
data.numberOfEnemys = numberOfEnemys;
data.mainWeaponID = mainWeaponID;
data.sideWeaponID = sideWeaponID;
data.helmetID = helmetID;
data.chestID = chestID;
data.arrowsID = arrowsID;
data.bootsID = bootsID;
data.gaunletsID = gaunletsID;
data.hasItem = hasItem;
data.arena = arena;
data.death = death;
data.main = main;
data.trainig = trainig;
data.Barracks = Barracks;
data.playerHeath = playerHeath;
data.addStamina = addStamina;
data.playerName = playerName;
data.items = items;
data.shopList = shopList;
// this the error when writing to file
bf.Serialize(file, data);
file.Close();
hasSave = true;
Debug.Log("saved player data");
}
when trying to rewrite the cod I cant get Application.persistentDataPath to work right
Answer by PlanarBit · Jun 17, 2020 at 05:53 PM
Inspect all types in PlayerData object graph. Make sure none of them derives from ScriptableObject.
thanks for your help it was something to do with the lists.
Your answer
Follow this Question
Related Questions
Binary Save System error 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Binary Save on android issues 1 Answer
Unity Saved Serialized Levels 0 Answers