I’ve been coding a game for my college and recently I decided to test it on a low-end laptop.
It runs without problems when testing it on the computer that I’m coding the game.
On that laptop, when the game starts, it should load a scene with a black screen and a button. However, it takes more than 10 minutes to load the desired scene. I don’t know where to start debugging so I can fix that problem.
The log file generated by Unity and the script to load the scene are below.
The flow is similar to this:
- The LoadingScreenManager.LoadScene() saves the scene index and loads the LoadingScene;
- Once the LoadingScene is started, it starts a coroutine and runs SceneManager.LoadSceneAsync() with the previously saved scene index;
- While the LoadSceneAsync is running, it keeps logging its progress;
4.LoadSceneAsync never completes.
Computer Info:
Log:
Script:
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadingScreenManager : MonoBehaviour
{
private static int _loadingScreenSceneIndex = 1;
private static int _sceneIndex = -1;
public Slider Slider;
public static void LoadScene(int sceneToLoad)
{
_sceneIndex = sceneToLoad;
SceneManager.LoadScene(_loadingScreenSceneIndex);
}
private void Start()
{
if (_sceneIndex < 0)
return;
StartCoroutine(LoadTargetSceneAsync());
}
private IEnumerator LoadTargetSceneAsync()
{
var operation = SceneManager.LoadSceneAsync(_sceneIndex);
while (!operation.isDone)
{
float progress = Mathf.Clamp01(operation.progress / 0.9f);
Debug.LogFormat("LoadingScene - sceneIndex:{0} progress:{1}",
_sceneIndex, progress);
Slider.value = progress;
yield return null;
}
}
}