Async

So i’ve read a lot of stuff about loading a level without lag. I have many scenes in my game so when i start loading multiple scenes one after another than it starts lagging after i load the 4-5 scene. This is just how my game is set up since its a color scheme game. So you choose a color thats off and it loads the next scene with different colors. I tried using loadlevelasync and it doesnt really do anything that i want it to do. Here’s the script for the load for async.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class LoadAsync : MonoBehaviour {
    AsyncOperation async;

   

   
    int[] levelNumbers = new int[15]{3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};

    void start ()
    {
        StartCoroutine ("load");
    }

    private IEnumerator load (){
        int randomIndex = Random.Range (0, levelNumbers.Length);
        Debug.LogWarning("ASYNC LOAD STARTED - " +
                         "DO NOT EXIT PLAY MODE UNTIL SCENE LOADS... UNITY WILL CRASH");
        async = Application.LoadLevelAsync(levelNumbers [randomIndex]);
        async.allowSceneActivation = false;
        yield return async;
    }

    public void onClick()
    {
        int randomIndex = Random.Range (0, levelNumbers.Length);

        async = Application.LoadLevelAsync(levelNumbers [randomIndex]);
        async.allowSceneActivation = true;
       
    }

    
}

It works without errors but when i play the game it still lags bad. Is there any possible way to get the darn game to not lag so bad??

LoadLevelAsync just does most of the loading work on another thread (any Awake, OnEnable, and Start methods will still occur on the main thread).

This allows you to have some type of animation during the loading process. Such as a progress bar.

Unlike LoadLevel which freezes all updating until it’s done loading.

This doesn’t mean it still won’t take a bit of time, especially if the scene is large. If you don’t give the player anything to do during that load time, it’ll just be a period of down time.

What you can do is pre-load the next scene ahead of time using the additive load. Set all the gameobject for that scene aside. And then enable them on click. Your code seems to select a random scene… so really, that random scene could be selected at any time. It’s not like it’s determinant on which thing is clicked.

Yeah i tried additive and when it loaded the new scene it loaded with the previous scenes stuff. So it basically just carried over. And im afraid if i make all objects a child of an empty object and destroy it on load then the game object may throw off the position of my objects.Plus since they are all random and each scene can be played multiple times than i dnt want to destroy them. I had some prefabbed scene faders in my game on each scene which was activated on start. I deleted them and now it runs much smoother. Im just going to add a custom fade script instead of the fancy fader i had.