Forum Discussion
GamerRoman22
12 months agoExplorer
Unity Scene Crash After Scene Load
Hi! I am experiencing an issue where my scene crashes the instant it loads. I have a loading scene and a script in there that loads the main scene after 15 seconds. Here is the loading script in case it is causing any problems:
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadingScreen : MonoBehaviour
{
[SerializeField]
private float delayBeforeLoading = 30f;
[SerializeField]
private string sceneNameToLoad;
private float timeElapsed;
private void Update()
{
timeElapsed += Time.deltaTime;
if (timeElapsed > delayBeforeLoading)
{
SceneManager.LoadScene(sceneNameToLoad);
}
}
}
This script has worked before, and I am unsure why it now crashes the main scene.
Thanks!
This script has worked before, and I am unsure why it now crashes the main scene.
Thanks!
2 Replies
Replies have been turned off for this discussion
- movcatExplorer
You should turn off the execution of Update after LoadScene. While Scene is loading, update may still execute even if you use Single and load immediately. Alternatively, using LoadSceneAsync is a better option to load the scene
- GamerRoman22Explorer
Thanks for answering! I am not sure how scripting works yet (this is someone else's script), although I really want to learn. I've asked ChatGPT, do you mean like this?
using UnityEngine;using UnityEngine.SceneManagement;public class LoadingScreen : MonoBehaviour{[SerializeField]private float delayBeforeLoading = 30f;[SerializeField]private string sceneNameToLoad;private float timeElapsed;private bool isLoading = false; // Flag to stop `Update` execution after scene load starts.private void Update(){// Stop executing `Update` after loading has started.if (isLoading)return;timeElapsed += Time.deltaTime;if (timeElapsed > delayBeforeLoading){isLoading = true; // Mark as loading to prevent further calls.LoadScene();}}private void LoadScene(){// Use asynchronous scene loading.SceneManager.LoadSceneAsync(sceneNameToLoad);}}
Thanks!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 3 years ago
- 3 years ago