- Home /
 
Is there a serialization class similar to JsonUtility but for Byte Serialization.
Hi everyone,
I am wondering if Unity provides serialization of their data that supports storing the data as bytes. JsonUtilitiy is really and I'm looking for a similar library to JsonUtility but for to-byte serialization.
There is the possiblity to use BinaryWriter/Reader, but it is rather inperformant.
Answer by Menyus777 · Apr 03, 2018 at 09:27 AM
I do my saving with binary writer, but please note that you need a container class for it, because Scripts deriving from MonoBehaviour cant use the new KeyWord, so when you deserialize it your deserialization will fail at runtime.
I Achieve this by implementing the ISerializable interface, in the container classes, and because the container classes aint derive from MonoBehaviour i can use the new Keyword at deserialization.
 public void Save_Game_State()
     {
         try
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream fs = File.Create(file_path);
             bf.Serialize(fs, Building_Containers);
             fs.Close();
         }
         catch (Exception ex)
         {
             print("Hiba a fájlbaírásnál! - Saving(Creating, writing)");
             print(ex.Message);
         }
     }
 
              Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Serializing an Action as XML? 0 Answers
Serialize class with serializable fields, 1 Answer
how to serialize unity variables? (Sprite, Image ...) 1 Answer