I currently have a coroutine that generates my world, which is almost working great! However I have another coroutine that I use to delete everything in the world if there ends up being a problem with the build process.
Within an if statement, if a condition is met the following code is run:
yield return StartCoroutine(ResetDungeonGeneration());
Debug.Log("We finished deleting");
The coroutine code looks like this:
IEnumerator ResetDungeonGeneration() {
Debug.Log("<color=red>**** STARTING DUNGEON RESET ****</color>");
var dungeon = GameObject.Find("Dungeon");
var dungeonPrefabs = dungeon.transform.childCount;
for(int i = 0; i < dungeon.transform.childCount; i++) {
Debug.Log("There are " + dungeon.transform.childCount + " to delete.");
Debug.Log("<color=red>*** Deleting " + dungeon.transform.GetChild(i).name + " ***</color>");
Destroy(dungeon.transform.GetChild(i).gameObject);
}
yield return null;
}
The deleting portion works fine. I see the expected logs in my console, the objects are removed from my inspector window. However then Unity just stops there. It doesn’t crash, I can still interact with things but I never see the message Debug.Log(“We finished deleting”);
If I add another log statement inside the ResetDungeonCoroutine right before the yield return null, it logs properly which makes it seem like it never considers itself finished. I am not noticing any errors so it must be something I am misunderstanding. Any help would be appreciated.