• 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 · coroutineyieldienumeratorcoroutinescoroutine 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Use Coroutine when object rotates 2 Answers

Coroutine Won't Stop Using IEnumerator 1 Answer

How to make tow Coroutines calling each other 1 Answer

Coroutines and states 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges