I am trying to solve this for over 1 month and still not getting it done. I've been trying a lot of different methods and the result is still the same. Code (CSharp): public void OnTriggerEnter() { LoadingObject.active = true; StartCoroutine(LoadAsyncOperation(SceneManager.GetActiveScene().buildIndex + 1)); } IEnumerator LoadAsyncOperation(int sceneindex) { AsyncOperation gameLevel = SceneManager.LoadSceneAsync(sceneindex); while(gameLevel.isDone != true) { yield return null; } } This is just one method. Anyway... The problem is that when I finish the level my loading animation doesn't show and instead it moves to the next level right away. And that's not all. I get 6-8 scenes with (is loading) and if I try to play I can't until all the scenes load. If anyone can tell me what to do and help me that would be really great. As i said, This problem pissed me off for over 1 month.
That's really very unclear. How do you know how many scenes are loading? What does it mean to "try to play" before they load? Where is this animation that you say isn't playing? What is "LoadingObject"? Why is your coroutine waiting in a loop but then not doing anything at the end of the wait? I don't see anything in there that would load more than one scene, so if you're sure about that part, then I can only guess that this is running multiple times (maybe several objects enter the trigger, or one object enters and leaves and re-enters) or you have additional scripts that are also trying to load scenes.
What I would do is set a bool just in case your method is being called more than once. You can also prevent the scene from activating until you want it too. Code (CSharp): private bool _loading = false; public void OnTriggerEnter(Collider other) { //Check if we are loading if (_loading) return; _loading = true; LoadingObject.active = true; StartCoroutine(LoadAsyncOperation(SceneManager.GetActiveScene().buildIndex + 1)); } IEnumerator LoadAsyncOperation(int sceneindex) { AsyncOperation gameLevel = SceneManager.LoadSceneAsync(sceneindex); gameLevel.allowSceneActivation = false; while (!gameLevel.isDone) { if (gameLevel.progress >= 0.9f) { //You wait here until you animation is finished before loading the level //You can check if it is finished or simply wait for x time like so yield return new WaitForSeconds(5f); //Now we allow the scene to load sceneAO.allowSceneActivation = true; } yield return null; } }
There are not multiple different scenes. "LoadingObject" is an empty game object where i've put my loading assets, animation and canvas. By "Try to play" I mean that when i start to play the level won't let me do it because the next "Lvl3" loads and the lvl starts over then.