Coroutine cancels for no reason
Hello, for my game I'm having a login screen that suddenly (without any code changes) stopped working.
Here is the relevant code:
public void OnClickLogin() {
field.Init();
server = field.selectedServer;
setPlayerPrefs();
_login.Login(inputUserName.text, inputPassword.text);
StartCoroutine(waitForLogin());
}
IEnumerator waitForLogin() {
int numberOfTries = 0;
while(_login.getAccountRunning && numberOfTries<60) {
numberOfTries++;
Debug.LogError("1. " + sessionController);
sessionController.sessionStatus = sessionController.sessionStatus + " .";
yield return new WaitForSeconds(0.5f);
}
Debug.LogError("2.");
if (numberOfTries < 60) {
Debug.LogError("3. " + field);
field.changeServer(server);
activateUIElements();
}
else { Debug.LogError("4."); }
}
The first Debug message ( Debug.LogError("1. " + sessionController);
) is shown twice, which is fine, but the rest of the code is never executed.
I didn't call StopCoroutine anywhere.
I tried restarting Unity, Visual Studio and my computer.
I tried going in with the Debugger, but the Coroutine behaves differently when I try to debug it.
OnClickLogin is called when clicking on the login button.
I'm not getting any more error messages, no Nullpointer exception, etc.
The rest of the code is continuing as intended. I'm even getting a welcome message for login in, but without the field.changeServer(server)
call it's not of any worth.
The last thing I changed before this happened was the y-Position of my UI-Camera as well as the layer of a canvas. Undoing these changes didn't help.
So finally my question: Why is the Coroutine getting canceled before it is finished?
Thank you for your help.
$$anonymous$$aybe it's helpful to know what exactly happens in the Debugger:
I started to Debug at numberOfTries++
, it completes the while loop only once, and jumps directly to else {Debug.LogError("4.")}
after the first yield return.
I added a fifth Debug line below and the Debugger shows it being executed, but the debug message doesn't appear in the console.
$$anonymous$$ysterious.