- Home /
Assign a variable using BinaryFormatter
Hi!
I have a few variables I need to be set using a binaryformatter when I deserialize. I just don't know how to do it. This is currently my code for this.
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(loadLocation + lvlName, FileMode.Append);
author = (string)bf.Deserialize(file);
name = (string)bf.Deserialize(file);
Thanks in advance!
How are you serializing the data ??
Have a look here: http://stackoverflow.com/questions/25746380/saving-loading-unity3d
@kdub I just noticed that I am using a regular StreamWriter to save so I never seralized anything. Wow. I failed. >_> But thanks for the link! I will check that out and the learning video. I will get back when I have done some edits to my script and see if it works.
Answer by RealMTG · Dec 31, 2014 at 01:01 AM
So I found a way of doing all this. I followed this tutorial: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading
It was that easy.