Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

yields stops the coroutine on 5.6

Discussion in 'Scripting' started by Deleted User, Apr 17, 2017.

  1. Deleted User

    Deleted User

    Guest

    So I made this game on unity 5.5 and today I decided to update it to 5.6 finally. I use coroutines to darken the scene when loading another scene, so after updating Unity I realised that whenever a coroutine hits "yield" it just stops the coroutine altogether. What's up with that? I see absolutely no errors whatsoever, it just dies out.

    I checked the timeScale, the object neither of them have any issues. I mean... it works on 5.5 after all. So what could be the problem here?
     
  2. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    It's difficult to say without any code to look at, please post your code so we easier see how it looks.
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Suhrahj

    Yes, what @Kona said -

    But I can say that I've used coroutines in editor play mode with 5.6 and they seem to be working OK.

    So it might be something else and I bet Unity wouldn't let this simple problem go unnoticed in release.
     
    Last edited: Apr 17, 2017
  4. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1. IEnumerator SceneOpener(GameObject canvas)
    2.     {
    3.         GameObject loadImage = new GameObject("LoadImage");
    4.         loadImage.transform.parent = canvas.transform;
    5.         Image loadimg = loadImage.AddComponent<Image>();
    6.         Color32 loadCol = new Color32(0, 0, 0, 255);
    7.         loadimg.color = loadCol;
    8.  
    9.         RectTransform loadRect = loadImage.GetComponent<RectTransform>();
    10.         loadRect.anchorMin = new Vector2(0, 0);
    11.         loadRect.anchorMax = new Vector2(1, 1);
    12.         loadRect.localScale = Vector3.one;
    13.  
    14.         loadRect.offsetMin = new Vector2(loadRect.offsetMin.x, 0);
    15.         loadRect.offsetMax = new Vector2(loadRect.offsetMax.x, 0);
    16.         loadRect.offsetMin = new Vector2(loadRect.offsetMin.y, 0);
    17.         loadRect.offsetMax = new Vector2(loadRect.offsetMax.y, 0);
    18.  
    19.         while (loadimg.color.a > 0f)
    20.         {
    21.             loadCol.a -= 51;
    22.             loadimg.color = loadCol;
    23.             yield return new WaitForEndOfFrame();
    24.         }
    25.  
    26.         UnityEngine.Object.Destroy(loadImage);
    27.     }
    here's my coroutine and I call it on Start() like this: StartCoroutine(SceneOpener(canvas));

    as I said this used to work without any problems on 5.5, I also thought that Unity wouldn't let such a simple thing pass by, but I really have no idea about the issue.

    As far as I've seen in the debug mode it just hits the yield and then the coroutine stops.
     
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    if it worked in prior unity versions and it does not now, then it is a bug so please file a bug.
     
  6. Deleted User

    Deleted User

    Guest

    The thing is it works when I try it on a newly created project, just not my own project.
     
  7. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    What else is going on in that scene? There is a good chance something else might be creating an issue.
    Does Unity freeze(as in you can't hit play to stop it) or the code just appears to stop running? If you put a debug in your while loop, does the debug keep printing? Does it print once or multiple times?

    Also, for fades and such in the future, you may consider a tweening engine. They handle them really well.
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    But does it happen in 5.5 ? if not then file a bug please.
     
  9. Deleted User

    Deleted User

    Guest

    it doesn't happen in 5.5, I will try filing a bug, but that's an unbelievably huge hassle for me with my "amazing" internet currently.

    @Brathnann I will try using that for the future but I am too far ahead currently. This is actually a completed project...
     
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Unless unity staff pop in this thread saying it's a known issue then your problem will not go away without bug report. This can be a really slim small reproduction scene if you like. So long as the scene works in 5.5, and does not work in 5.6.
     
  11. aicam-spain

    aicam-spain

    Joined:
    Apr 17, 2017
    Posts:
    3
    I see that you also use a Canvas in the script that's giving you the problem. We've been testing (and posting our results here), and for us the cause seems to be the use of canvas and coroutines in the same script...

    We don't know what causes this yet, although it looks like a bug. We've rolled back to 5.5 for now in hopes that this get's solved.
     
  12. Deleted User

    Deleted User

    Guest

    @aicam-spain canvas and coroutines being in the same script causing the problem? That is really strange. Nonetheless I have filed a bug report today, hopefully there will be a fix for this. Although in this case I cannot remove the canvas usage in my script, but I will try it elsewhere as you've pointed out.
     
  13. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,911
    It seems like WaitForEndOfFrame is the most obscure of all the yields. The docs (which seem to have a wrong code example) say it's meant for taking a screen shot (which you could also do in, ummm, OnRenderImage?) I'm also wondering if Application.CaptureScreenshot doesn't make it obsolete. So it's possible 0 people in the world are using WaitForEndOfFrame for it's intended purpose. It sort of makes sense for it to bug out with a canvas, since that might draw last, affecting when the frame really ends.

    For code just fading an alpha, I think yield return null; would be the more common way.
     
  14. Deleted User

    Deleted User

    Guest

    @Owen-Reynolds well they should have said it more obviously I guess, but I assure you the problem is not 'WaitForEndOfFrame', I tried other yield returns, it just dies out whatever I use.
     
  15. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,381
    If you can reproduce it, file a bug report with the scene.
     
  16. Deleted User

    Deleted User

    Guest

    "Nonetheless I have filed a bug report today"
     
  17. Deleted User

    Deleted User

    Guest

  18. briancullen13

    briancullen13

    Joined:
    Apr 3, 2015
    Posts:
    3
    I've had the same issues with simple coroutines and even some function calls when moving up to 5.6. I tried to make a bug report but when a make a new project with a simplified version of the issues the problem disappears.
     
  19. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    88
    I'm seeing this too... Is there any solution?

    I even tried updating to 2017 to get the fix for issue #904415, since that certainly sounded like what was going on, but at least in my case, the problem persists. I'm currently looking into isolating the issue.