Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by SNS_Case · Jun 04, 2015 at 09:26 PM · coroutineyieldcoroutinesienumeratorcoroutine errors

Coroutines not passing yield

I have an issue with a level loader I've written where the following code is not completing:

 IEnumerator LoadAsync(int i) {
     Debug.Log ("Loading...");
     aop = Application.LoadLevelAsync(i);
     aop.allowSceneActivation = false;
     Debug.Log ("Post-LLA");
     yield return aop;
     Debug.Log ("Load done time: " + Time.time);
     loading = false;
     levelReady = true;
     yield return new WaitForSeconds(1f);
     //aop.allowSceneActivation = true; (this happens in the Ready function)
     Ready ();
 }


The aop variable is defined as an AsyncOperation. Some background here, I had another yield return new WaitForSeconds(1f) line preceding the yield return aop line, and it would hang on that as well. I get the debug output in the console before any yields. I'd originally started writing this as a problem with LoadLevelAsync/AdditiveAsync, but then discovered none of the yield calls were getting through. I've tried calling with both StartCoroutine(LoadAsync(i)) and ("LoadAsync", i) just to make sure there wasn't some odd change I missed.

It is being called from this function on an object tagged for DontDestroyOnLoad():

 public void LoadLevel (int i) {
     loading = true; levelReady = false;
     Application.LoadLevel("Loading");
     PercentageID pid = FindObjectOfType<PercentageID>();
     if (pid != null) percentageText = pid.GetComponent<Text>();
     loadContent = GameObject.Find ("LoadingContent");
     Debug.Log ("Load start time: " + Time.time);
     StartCoroutine ("LoadAsync", i);
 }

Any ideas on what's happening? Is this a bug with the latest versions of Unity? (I was on 5.0.1 originally and now the current 5.0.2)

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by jctz · Jun 10, 2015 at 05:32 AM

If you're 100% sure that your object isn't being destroyed, then I would suggest that you add a 'yield return null' at the very top of LoadAsync(). This is because Application.LoadLevel() doesn't actually work right away and only loads the specified level at the end of the current frame. Without it, you're effectively doing Application.LoadLevel() and Application.LoadLevelAsync() on the same frame. Who knows how Unity will respond?

Comment
Add comment · Show 2 · Share
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 SNS_Case · Jun 10, 2015 at 11:49 PM 0
Share

You were right, I double-checked and it was still getting destroyed. For some reason I neglected to consider that the parent transform it was a child of was not tagged to be kept between level loads, so it just removed the whole manager container. I may feel a bit dumb, but I'm glad you had me double-check, so thanks for that!

avatar image jctz · Jun 10, 2015 at 11:57 PM 1
Share

Awesome, I'm glad you got yourself unblocked!

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

21 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

Related Questions

Collection Change During Iteration 0 Answers

Coroutines and states 1 Answer

Coroutine Not Working 2 Answers

Coroutine sequence not running properly 1 Answer

[ Coroutine: Move Next ] CPU usage 0 Answers


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