Hello everybody,
I have a question. I am performing a repeat loop with a FOR. In this “FOR”, I’m calling a “YIELD RETURN NULL” in each repetition of the loop. The problem is that my iterator is always 0, and the loop eventually becomes infinite!
I recorded a video with the problem:
1
And the code:
IEnumerator ProcessSaveGame () {
_isSaving = true;
Data = new PlayerData();
var buildings = StructuresManager.GetBuildingList();
if (buildings != null && buildings.Count > 0)
{
yield return StartCoroutine(SaveBuildings(buildings));
}
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/gameData001.dat");
bf.Serialize(file, Data);
file.Close();
_isSaving = false;
}
IEnumerator SaveBuildings (List<Building> buildings) {
for (int i = 0; i < buildings.Count; i++)
{
AddBuildingData(buildings*);*
-
yield return null;*
-
}*
- }*