So I am curious on how I can fix this. I'm trying to async load my scenes/levels and it works but it lags due to it loading the scene in one frame. I've looked this up for a while, and it seems as though it loads some of the level in the background but loads all OnAwake and Start calls into one frame? I'm not entirely sure but I'm assuming that's what's happening. Unfortunately, all the resources I've looked up, none have a definite solution to the lag spikes. Back to me being curious, if I separated my level into a few scenes and loaded each scene by itself in it's own frame, and then merge those scenes into one, will that give me a smoother transition or will that give me more problems?
In unity asyc load means read all bytes from disk on another thread. Your awakes and starts are run next frame after all data is loaded and they must run on main thread, so there's no way to run them in a background thread. But you may use coroutines to smudge the initialization for few frames.
Thanks for replying! So I am using a script with coroutines that starts the loading process after I've faded into the loading screen. Here's the code: Code (csharp): public GameObject fadeOut; void Start () { StartCoroutine(waitForProgram()); } IEnumerator waitForProgram() { yield return new WaitForSeconds(1); StartCoroutine(LoadAsyncScene()); } IEnumerator LoadAsyncScene() { AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(Globals.LevelOn); asyncLoad.allowSceneActivation = false; yield return (asyncLoad.progress > 0.9f); fadeOut.SetActive(true); StartCoroutine(loaded(asyncLoad)); } IEnumerator loaded(AsyncOperation sync) { yield return new WaitForSeconds(1); sync.allowSceneActivation = true; } This is what I have so far in my loading script, the 'waitForProgram' and 'loaded' coroutines are for creating the proper transitions of fading in and then fading out. 'LoadAsyncScene' is the function I'm targeting in terms of the loading functionality. This was tested and works but it does persist with the lag during load. So when you referred to using coroutines to stretch out the initialize process, what could I improve or input to achieve that?
I mean, if you have 1000 objects initializing in one frame and it causes the lag, then you may use a coroutine to initialize, say, 10 of them per frame so they won't hurt performace badly.