Search Unity

Scene Changing bug? (Video Included)

Discussion in 'Editor & General Support' started by Webbstre, Aug 22, 2017.

  1. Webbstre

    Webbstre

    Joined:
    Mar 7, 2015
    Posts:
    41
    Hello all. I'm about to pull my hair out with the problem I'm having changing scenes. It's fully explained and shown in this youtube video:



    The script I'm using to change scenes (with the bits to try to determine if scenes are unloading or not) looks like this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class QuitToSomewhere : MonoBehaviour {
    7.  
    8.     private void Start()
    9.     {
    10.         DontDestroyOnLoad(gameObject);
    11.     }
    12.    
    13.     public void LoadAScene(string sceneToLoad)
    14.     {
    15.         int currentScene = SceneManager.GetActiveScene().buildIndex;
    16.         SceneManager.LoadScene(sceneToLoad, LoadSceneMode.Single);
    17.         SceneManager.UnloadSceneAsync(currentScene);
    18.  
    19.         Debug.Log("Should have changed scenes and unloaded old now. " + SceneManager.sceneCount.ToString());
    20.         StartCoroutine(SceneCountCheck());
    21.     }
    22.    
    23.  
    24.     IEnumerator SceneCountCheck()
    25.     {
    26.         Debug.Log("Current Scene Count: " + SceneManager.sceneCount.ToString());
    27.  
    28.         yield return new WaitForSeconds(1);
    29.         StartCoroutine(SceneCountCheck());
    30.     }
    31.  
    32.  
    33. }
    34.  

    Seriously, any help is appreciated. This is the last step for me to start alpha testing my game, and it's like running into a brick wall. Google hasn't been a lot of help either. :(
     
  2. Webbstre

    Webbstre

    Joined:
    Mar 7, 2015
    Posts:
    41
    After searching nearly everywhere, I discovered the problem. I was pausing the game (Time.timescale = 0) when opening the menu, so the game was still paused after changing scenes. Adding a Time.timeScale = 1; line fixed it.