Ienumerator and coroutine

I have just a question for the saving section. I want to know so I can better understand why this is done.
In the SavingSystem.cs And SavingWrapper.cs they do a coroutine. Why do they do that rather than just calling the function?

We have a lot going on in these coroutines, and they have to happen over several frames…

  • We want to wait for the fader to fade the screen out
  • We want to save the scene
  • We want to load the new scene, this can take several seconds.
  • We want to restore the scene, move the player and save it again
  • We want to fade the scene back in.

Since Fading and Loading can take multiple frames, often several seconds, to occur. That is the sort of thing we want to happen via a coroutine. Additionally, if you were to simply call the underlying methods that they wait for and carry on, the fader would never actually fade, and the game would freeze up and become unresponsive while the new scene was loading.

So, The way I’m reading this is that the coroutine stops other functions from happening until that coroutine is done running because that coroutine is doing something special and should not be interrupted or stopped by another function running. Is that correct?

So, for example you want the scene transaction to run so you go from scene to scene. But if you hit a button that makes the player swing his sword the function for the scene changing will be interrupted and canceled. so, put it in a coroutine so it doesn’t get interrupted.

It’s more like… the coroutine runs and the main thread is allowed to continue on it’s merry way…

The two things are happening at the same time. Theoretically, while the new scene is loading (these things take time), you actually COULD hit that button and swing that sword and the animation would play.

Privacy & Terms