Skip to main content

Coroutine stuck Infinite while loop

This could be due to the use of Time.time which is known to have issues in our engine and it will not update whilst in a coroutine. Consequently, any code using Time.time within a coroutine will most likely produce incorrect calculations, as this variable is not updating, an infinite while loop is likely to occur.

Possible solution:

  • Use time.DeltaTime instead of Time.time if possible, or some other value which can be manually incremented with time.DeltaTime. For example:
//initialised before the coroutine starts
float newTime;

//not inside of the coroutine
newTime = Time.time + time.DeltaTime;

images-medium