0
\$\begingroup\$

I have two scenes in the Hierarchy when running the game. And this script attached to empty GameObject:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadScenes : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        if (!SceneManager.GetSceneByName("The Space Station").IsValid())
        {
            SceneManager.LoadScene(1, LoadSceneMode.Additive);
            StartCoroutine(WaitForSceneLoad(SceneManager.GetSceneByName("The Space Station")));
        }
    }

    public IEnumerator WaitForSceneLoad(Scene scene)
    {
        while (!scene.isLoaded)
        {
            yield return null;
        }
        SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));
    }
}

But it's taking like 3-4 seconds until it's getting to the line:

SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(1));
\$\endgroup\$
1
\$\begingroup\$

Scene loading always depends on resource(prefabs, gameobjects, audios, textures, etc.) usage. If scene has a lot of objects in it, or scripts instantiate objects in awake or start methods, scene loading will take much more time.

Async Object Management in Unity3D Forum.

LoadSceneAsync Unity3D Docs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.