spliting my code in a coroutine with yield return null?

Hi,
I’ve got an idea to split some of my heavy coroutines to execute them in multiple frames. but I got some weird result, in some cases it’s working and in some it’s not.
here is a piece of code that doesn’t work:

 IEnumerator LoadSettings()
    {
        loading = true;
        
        QualitySettings.masterTextureLimit = 4 - GameSettings.TextureQuality;
        QualitySettings.lodBias = GameSettings.LODBias;
        QualitySettings.anisotropicFiltering = GameSettings.Anisotropic ? AnisotropicFiltering.Enable : AnisotropicFiltering.Disable;
        QualitySettings.antiAliasing = GameSettings.AntiAliasing;


        //if user wants some dyamic lighting we must enable useLightProbe option in every meshRenderer and SkinnedMeshRenderer
        if (!GameSettings.DynamicLighting)
        {//user doesn't want dynamic lighting
            var meshRenderers = FindObjectsOfType<MeshRenderer>();
            var skinnedMeshRenderers = FindObjectsOfType<SkinnedMeshRenderer>();
            foreach (var meshRenderer in meshRenderers)
            {
                meshRenderer.useLightProbes = false;
                yield return null;
            }
            foreach (var skinnedMeshRenderer in skinnedMeshRenderers)
            {
                skinnedMeshRenderer.useLightProbes = false;
                yield return null;
            }
        }
        else
        {//user wants dynamic lighting
            var meshRenderers = FindObjectsOfType<MeshRenderer>();
            var skinnedMeshRenderers = FindObjectsOfType<SkinnedMeshRenderer>();
            foreach (var meshRenderer in meshRenderers)
            {
                meshRenderer.useLightProbes = true;
                yield return null;
            }
            foreach (var skinnedMeshRenderer in skinnedMeshRenderers)
            {
                skinnedMeshRenderer.useLightProbes = true;
                yield return null;
            }
        }
      
        yield return null;
        //user can customize game resulotion to decrease or increase the fill rate of the game
        Screen.SetResolution(GameSettings.ResulotionWidth, GameSettings.ResulotionHeight, true);

        //locking the aspect
        var _cameraGameObjects = FindObjectsOfType<Camera>();
        foreach (var camera in _cameraGameObjects)
            camera.GetComponent<Camera>().aspect = 1920f / 1080f;
        loading = false;

}

I used Visual Studio and inserted some breakpoints and I noticed my code doesn’t reach to this line:

skinnedMeshRenderer.useLightProbes = true;

I am pretty sure that I have some SkinnedMeshRenderers in my scene.

So whats the problem with this coroutine?

I think you should use just 1 yield return null at the very bottom of the coroutine function

Well, i suggest you set your breakpoint at the start of your coroutine and step through it and inspecting some values. So you can check what value “GameSettings.DynamicLighting” has and if FindObjectsOfType actually returned anything. Just hover over a variable while the process is paused and you’re inside the coroutine.

In VS you have to press F10 to “step over” the next instruction or F11 to “step into” which only makes sense for lines that call other methods.

Are you sure you attached VS as debugger? If you don’t breakpoints are pretty useless ^^. I’m not sure if you can actually place breakpoints in coroutines but it’s worth a try.