添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

To save my game I am using the TestSerializer script which is attached to the Save Game Manager in my scene. My game saves correctly however after quitting and starting the game back up my saves all disappear apart from the very first game state that had been saved.

Ive heard that the problem could be that the Serializer is only allowed to save once, can someone help me with this?

This is my first post here. Call a load at the beginning. So on Awake() make sure that you have called your Load() function as well, if you created one. If you haven’t you should make one. If you don’t do that it will save everything fine but will not load them. Here is some of code to help you out:

void Awake(){
		if (player == null) {//This creates one object that will be used to persist data between scenes
			DontDestroyOnLoad (this.gameObject);//Makes this a persistant object
			player = this;
			Load ();//This is where I am loading the values
		else if (player != this) {
			Destroy (this.gameObject);
public void Load(){//Grabs the file and pulls the data back out.
		if(File.Exists(Application.persistentDataPath + Path.PathSeparator +"Mazed.dat")){
			BinaryFormatter bf = new BinaryFormatter();
			FileStream file = File.Open (Application.persistentDataPath + Path.PathSeparator +"SomeFile.dat", FileMode.Open);
			PlayerData data = (PlayerData)bf.Deserialize(file);
			health = data.health;
			xp = data.xp; // this is loading the saved "XP" to the public xp int;
			gold = data.gold; // this is loading the saved "gold" to the public gold int;
			magic = data.magic; // this is loading the saved "magic" to the public magic int;
			spark_found = data.spell_spark;
			file.Close();
public void Save(){//Saves data as a binary file to the proper folder for each OS.
		BinaryFormatter bf = new BinaryFormatter ();
		FileStream file = File.Create (Application.persistentDataPath + Path.PathSeparator +"SomeFile.dat");
		PlayerData data = new PlayerData ();
		data.health = health;
		data.xp = xp;
		data.magic = magic; //saves whatever is in "magic" to something called magic
		data.gold = gold; //saves whatever is in "gold" to something called gold
		data.spell_spark = spark_found; //saves whatever is in "spell_spark" to something called spell_spark
		bf.Serialize (file, data);
		file.Close ();

I hope this helps!

It could be that due to te array size, the saves are not persisting. This is a known bug with Unity Serializer. Here is a solution that works:

http://whydoidoit.com/forums/topic/saves-not-persisting-due-to-list-or-array-size/