- Home /
Why isn't this coroutine fully firing?
This weird bug is throwing me for a loop.
I'm calling this coroutine:
private IEnumerator LoadDelayed(Vector3 position) {
Debug.Log("Part 1");
yield return new WaitForSeconds(1);
Debug.Log("Part 2");
this.transform.position = position;
Debug.Log(this.transform.position + ", " + position);
Game.PAUSED = false;
}
But the output is only this forever:
It should also be noted that the none of code after the WaitForSeconds executes, not just the Debug.Log
Edit: I've found a different workaround for my purposes, but I'd still be curious to know why it wasn't working. The coroutine is being called after loading a scene, could that be the issue?
Answer by mujpir · Mar 16, 2019 at 10:48 PM
There may be 2 reason for this to happen :
Your Time.timeScale is set to zero . So your code is stopped at WaitForSeconds(1).Try using WaitForSecondsRealTime(1) to see if execution continue?
2.Your Gameobject that has this scripts attached to it is destroyed right after Debug.Log("1") is called when new scene is loaded . Make sure that your gameObject is still alive or call
dontDestroyOnLoad(gameObject)
at the Start() or Awake() of your coroutine script to prevent your GameObject to be destroyed after loading new scene .
Your answer
Follow this Question
Related Questions
WaitForSeconds isnt working 1 Answer
What is the best method for setting up a variable wait time in a coroutine? 1 Answer
Why isn't my simple coroutine working? (and how can I make it infinite?) 2 Answers
my script is broken again(enemy refuses to stop seeing me) 1 Answer
Ienumerator wait for event 0 Answers