I would like to test if the progress bar matches the ‘actual’ scene loading time.
I implemented the progress bar using the AsyncOperation class.
Here is the code:
public class Loading2 : MonoBehaviour
{
public GameObject LoadingScreenObj; //UI component
public Slider slider;
AsyncOperation async;
public void Awake()
{
StartCoroutine(LoadingScreen("SecondScene"));
}
IEnumerator LoadingScreen(string scene)
{
LoadingScreenObj.SetActive(true);
async = SceneManager.LoadSceneAsync(scene);
async.allowSceneActivation = false;
while (async.isDone == false)
{
slider.value = async.progress;
if (async.progress == 0.9f)
{
slider.value = 1f;
async.allowSceneActivation = true;
}
yield return null;
}
}
}
But when I perform a test play on my Standalone Build(not Unity Editor!), its progress bar goes through too fast.
So I’m not sure if the progress bar ‘accurately’ represents the time it takes to load the second scene.
So I created about 1200 objects manually in the hierachy of the second scene. and I attached components such as ‘RigidBody2D’ and ‘Light’ to each object.
The progress bar seems to be moving a bit slower than loading an empty scene, but it is still too fast to have confidence in the test results.
There’s a general misconception about scene loading.
The ‘progress’ you can query is only based on the asynchronous part of loading a scene. ‘Loading’ refers to getting everything ready to use, such as resources that have to be loaded from the hard disk into memory, and some other initializations.
The ‘progress’ does not take into account the actual phase in which everything ‘awakes’ in the new scene, that’s why the max value you’ll get until scene activation is 0.9f. Kinda like ‘hey, the asynchronous part is done’.
The following line generally works
if (async.progress == 0.9f)
I’d still use Mathf.Approximately or something similar, just to be sure.
Back to why you seem to see not much of difference:
As mentioned earlier, the asynchronous part will only do stuff in the background, like loading resources etc. Since you’ve probably just added 1200 primitive gameobjects to your scene, there’s not much to load asynchronously, as the instantiation and component initialization (like Awake etc) will be done on the main thread again.
If you wanted to see a real difference, you’d either need a slow computer or a complex scene that requires more assets to load.