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);
}
}