I was updating my scene loading code and after testing, for some reason unity just froze.
I simply commented out my new code temporarily and I still had the problem.
I figured out that for some reason when I do a yield return SceneManager.LoadSceneAsync("LoadingScreen"); allowSceneActivation will be false for some reason. It wasn’t like this before… I could just write the code mentioned and it would pause my coroutine until the scene loads. I haven’t updated unity or done anything that would do this so for me it’s unclear what just happened. Now with this set to false I can’t make my code wait out until the scene loads (I need it because it can’t find my texts without loading the loading scene) even something like while(!TheAsyncOperationsName.isDone) {} freeze unity
My code (with comments edited out 'cause of noobish code):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class LoadingScene : MonoBehaviour {
public static LoadingScene loadingScene;
private Text LoadText;
private Text SpaceText;
void Awake()
{
if (loadingScene == null)
{
DontDestroyOnLoad(gameObject);
loadingScene = this;
}
else if (loadingScene != this) { Destroy(gameObject); }
}
void Start() {
}
// Update is called once per frame
void Update() {
}
public void LoadScene(int scene)
{
StartCoroutine(AsynchronousLoad(scene));
}
IEnumerator AsynchronousLoad(int scene)
{
yield return null;
yield return SceneManager.LoadSceneAsync("LoadingScreen");
AsyncOperation ao = SceneManager.LoadSceneAsync(scene);
ao.allowSceneActivation = false;
while (!ao.isDone)
{
float progress = Mathf.Clamp01(ao.progress / 0.9f);
LoadText = GameObject.FindWithTag("LoadTXT").GetComponent<Text>() as Text;
LoadText.text = ("Töltés: " + Mathf.Round(progress * 100) + "%");
if (ao.progress == 0.9f)
{
SpaceText = GameObject.FindWithTag("SpaceTXT").GetComponent<Text>() as Text;
SpaceText.text = ("Nyomd meg a space-t vagy éríntsd meg a képernyőt a folytatáshoz!");
if (Input.GetKeyDown(KeyCode.Space) || Input.touches.Length != 0)
{
ao.allowSceneActivation = true;
}
}
}
yield return null;
}
}
ps.: I’m on Unity 5.5 also, some text are in hungarian because the game I’m making is hungarian