yields stops the coroutine on 5.6

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?

It’s difficult to say without any code to look at, please post your code so we easier see how it looks.

@

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.

IEnumerator SceneOpener(GameObject canvas)
    {
        GameObject loadImage = new GameObject("LoadImage");
        loadImage.transform.parent = canvas.transform;
        Image loadimg = loadImage.AddComponent<Image>();
        Color32 loadCol = new Color32(0, 0, 0, 255);
        loadimg.color = loadCol;

        RectTransform loadRect = loadImage.GetComponent<RectTransform>();
        loadRect.anchorMin = new Vector2(0, 0);
        loadRect.anchorMax = new Vector2(1, 1);
        loadRect.localScale = Vector3.one;

        loadRect.offsetMin = new Vector2(loadRect.offsetMin.x, 0);
        loadRect.offsetMax = new Vector2(loadRect.offsetMax.x, 0);
        loadRect.offsetMin = new Vector2(loadRect.offsetMin.y, 0);
        loadRect.offsetMax = new Vector2(loadRect.offsetMax.y, 0);

        while (loadimg.color.a > 0f)
        {
            loadCol.a -= 51;
            loadimg.color = loadCol;
            yield return new WaitForEndOfFrame();
        }

        UnityEngine.Object.Destroy(loadImage);
    }

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.

if it worked in prior unity versions and it does not now, then it is a bug so please file a bug.

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

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.

But does it happen in 5.5 ? if not then file a bug please.

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…

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.

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.

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

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.

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

If you can reproduce it, file a bug report with the scene.

“Nonetheless I have filed a bug report today”

Apparently it’s because of this: Unity Issue Tracker - Coroutines stop working if you create a GameObject in the runtime, set its parent and attach any UI component to it

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.

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.