Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Jonas_F · Dec 01, 2016 at 11:30 AM · coroutinecoroutinescoroutine errors

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jonas_F · Dec 01, 2016 at 11:53 AM 0
Share

$$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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

81 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Array reference being changed without me knowing, or, When a coroutine is run on a monobehavior and then stopped with StopCoroutine (coroutine) it stops the same coroutine being run on another instance of the same monobehavior on a different object. 1 Answer

Why isn't my coroutine working when I call it from another script. 0 Answers

Coroutine Not working properly. 1 Answer

Trouble with coroutine 0 Answers

How do I stop an automatically repeating Coroutine? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges