LoadSceneAsync causing stutters after updating to latest 2021 LTS

I have a basic loading screen setup, similar to the one outlined in the Unity documentation, with a call to SceneManager.LoadSceneAsync() inside of a coroutine, loading the main scene of my game. I also have a sort of spinning animation to show that the game is not frozen while it loads. This spinning animation would animate perfectly smoothly while the game loaded when I was using Unity 2021.3.8, however after upgrading to 2021.3.45 it now stutters and does not play back smoothly. I have made no changes to the loading scene code between versions. I also have tested on the latest 2022 LTS, and the issue persists in that version (however I prefer to stay on 2021 if possible).

I have included the script which handles the loading. The animations actually happen in another monobehavior, which just rotates the attached objects transform based on Time.time. I have tried moving the animations into this script and it makes no difference.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadMainSceneHandler : MonoBehaviour
{
    public Transform loadingBar;
    bool started_loading = false;
    bool doLoadingAsync = true;
    
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
    }
    
    void Update()
    {
        if(!started_loading)
        {
            Application.targetFrameRate = 60;
            started_loading = true;
            StartCoroutine(LoadMainSceneCoroutine());
        }
    }
    
    IEnumerator LoadMainSceneCoroutine()
    { 
        Application.backgroundLoadingPriority = ThreadPriority.High;
        if(doLoadingAsync)
        {
            AsyncOperation asyncLoading = SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
            while(!asyncLoading.isDone)
            {
                float AdjustedProgress = asyncLoading.progress;
                if(AdjustedProgress < 0.9f)
                {
                    if(AdjustedProgress < 0.0125f)
                    {
                        AdjustedProgress = Mathf.InverseLerp(0.0093f, 0.0125f, AdjustedProgress);
                        AdjustedProgress = Mathf.Lerp(0f, 0.9f, AdjustedProgress);
                    }
                    else
                    {
                        AdjustedProgress = Mathf.InverseLerp(0.0125f, 0.9f, AdjustedProgress);
                        AdjustedProgress = Mathf.Lerp(0.9f, 1f, AdjustedProgress);
                    }
                }
                else AdjustedProgress = 1.0f;
                loadingBar.localScale = new Vector3(AdjustedProgress, 1f, 1f);
                yield return null;
            }
            
        }
        else SceneManager.LoadScene(1, LoadSceneMode.Single);
        yield return null;
        yield return null;
        Application.targetFrameRate = -1;
        Application.backgroundLoadingPriority = ThreadPriority.BelowNormal;
        Destroy(gameObject);
    }
}

Before upgrading, or after upgrading when you encounter odd issues, be sure to delete the Library folder (with project closed!) and try again.

Also double check whether the issue is due to upgrading. Copy the latest project, delete the Library, and open it in 2021.3.8. If this works fine, the best course of action without investing too much time is to try and find the 2021.3 version that introduces this issue and stay one patch level below that.

However it wouldn’t be surprising if you find that stuttering occurs in the old version too and the cause is something else entirely.

Try setting this to a lower value. Stutter could also be from the main thread not getting enough time to do much processing and the “intensity” of this setting may have changed slightly but noticably in your case.

Thanks for the advice. Unfortunately, I’ve already tried most of your suggestions before posting. I decided to try everything again for good measure, including downgrading in place (rather than using git to restore the old 2021.3.8 version), and unfortunately downgrading is the only thing that does seem to fix the issue.

I will attempt to binary search the Unity versions to find which version introduced the issue, since that might be useful to Unity developers. Will update this thread when I know. The only real reason I’m upgrading versions at all is because Nintendo expects a newer version of their SDK for submissions, but I will apply for a waiver on this from them.

(EDIT FOLLOWS)

I determined that the exact build where the issue shows up is 2021.3.40, with the previous 2021.3.39 build not showing the issue.

Looking at the build changes, the only thing that I can see that maybe could have caused this issue is

Asset Bundles: Improve parallelism of the Main Thread integration and the Preload Manager thread. (UUM-70670)

It may be worth noting that I am still using Visual Studio 2019.

If it would help then I can file a bug report, though I’m not 100% sure where I even do that. For me personally, the version without the issue is recent enough that I can ship the game on it, so it won’t personally cause any problems at the moment.

(EDIT 2) I have now filed a bug report, so hopefully whatever the regression is in 2021.3.40 can get resolved

Any update on this?

Not really. I sent off the bug report, but I haven’t heard anything back from Unity about it. I’m just sticking with 2021.3.39 for now.