Coroutines stop randomly (Unity glitch)
Hi all. I'm having a strange glitch with Unity at the moment.
IEnumerator ExtendLaser()
{
emissionPS.Play();
while (scaX <= (laserLength / 4))
{
scaX = scaX + 0.002f;
yield return new WaitForSeconds(0.008f);
}
while(scaX >= (laserLength / 4) && scaX <= (laserLength / 2.5f))
{
scaX = scaX + 0.002f;
yield return new WaitForSeconds(0.004f);
}
while (scaX >= (laserLength / 2.5f) && scaX <= laserLength)
{
scaX = scaX + 0.002f;
yield return new WaitForSeconds(0.0008f);
}
scaX = laserLength;
}
IEnumerator RotateTurret()
{
while(amount < 2)
{
amount = amount + 0.1f;
headYRot = headYRot - amount;
turretHead.transform.Rotate(-90f, headYRot, 0f);
yield return new WaitForSeconds(turnSpeed / 100f);
}
while(deactivate == false)
{
headYRot = headYRot - amount;
turretHead.transform.Rotate(-90f, headYRot, 0f);
yield return new WaitForSeconds(turnSpeed / 100f);
}
while(amount > 0)
{
amount = amount - 0.1f;
headYRot = headYRot - amount;
turretHead.transform.Rotate(-90f, headYRot, 0f);
yield return new WaitForSeconds(turnSpeed / 100f);
}
}
These two coroutines in one of my scripts stop completly randomly for no reason at all. The coroutines are both called from the Start() function. I know for sure that this is a Unity issue and not a problem with my code. I'm setting the two float variables 'scaX' and 'amount' to public so I can see them in the inspector, and it is not to do with these variables. For example, when Unity randomly stops my 'RotateTurret' coroutine, amount is on '0.1' when the while loop is meant to keep repeating until it equals 2.
I also know this is a glitch with Unity because this happened again a few days ago, Unity crashed for some reason after an hour of the glitch going on and then it was fixed when I restarted Unity. However, restarting Unity now will not fix it. Is there anyone else who knows about this glitch and knows a solution to this? Very annoying because I cannot get on with any work when this glitch is happening.
Thanks all!
@HyperGamer87 , Didn't check the code, but I bet you'll be better off posting this on the forums, or filing a bug report.
Oh of course, that would be a good idea. It worked fine before the latest update, maybe Unity broke something :/ Thanks!
if you did not disable gameobject with that script running then it is definite a bug or you have some random code call deactivate = true
Yeah, it's very weird. The gameobject definitly stays active through playmode. I even have another coroutine that's called from Start() and that usually works, and sometimes these two coroutines shown here work too, but most of the time they don't work...