XMLSerializer does not save unless I open Monodevelop?

Hi people,

I’ve ran into a something very weird. I have a GameManager that saves the data to XML when the app is closed. However, I noticed that when I had Monodevelop on, it works like what I expected. But when Monodevelop is not running, the values didn’t get saved into my XML file. Has anyone else encountered anything like this before?

void OnApplicationQuit() 
	{

		foreach(BuildingManager buildingLoaded in buildingManagerList)
		{
			bXML.ID = buildingLoaded.ID;
			bXML.name = buildingLoaded.buildingName.text;
			bXML.unlocked = buildingLoaded.unlocked;
			bXML.productionPC = buildingLoaded.idleEarning;
			bXML.productionTime = buildingLoaded.timer;
			buildingContainer.buildingList.RemoveAt(j);
			buildingContainer.buildingList.Insert(j, bXML);         //Overwrite value on list
		}
	

		XmlSerializer serializer = new XmlSerializer(typeof(BuildingContainer));

		FileStream stream = new FileStream(Application.dataPath + "/Resources/" + pathToSave, FileMode.Create);

		serializer.Serialize(stream, buildingContainer);

		stream.Close();

		Debug.Log("saved");
	}

I’m sure that my Load was correct as it was able to read in values correctly and display it in the game. I used the standard practise to save the file; Create file, Write file, Close file.

Anyone?

I’ve found the answer.

using UnityEditor;

AssetDatabase.Refresh();  

after writing to file is all I needed. Thanks!

I will keep this thread just in case anyone has the same problem in the future.