- Home /
Check if Scene exists in Build Settings?
Hi there, I am trying to load levels by incrementing their build index.
 If the build index doesn't exist, I want to load the menu instead.
if(/*this build index exists*/) { SceneManager.LoadSceneAsync(levelIndex++); } else { // load menu } 
 how would I do this? 
 many thanks!
All settings are serialized in files, so you need to find that file, and check it.
Answer by Hellium · Nov 22, 2019 at 10:47 PM
 if(levelIndex < SceneManager.sceneCountInBuildSettings)
 {
   SceneManager.LoadSceneAsync(levelIndex++);
 }
 else
 {
     // load menu
 }
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-sceneCountInBuildSettings.html
Answer by MajeureX · Jul 15, 2020 at 04:13 PM
If you have the path of the scene, you can use the SceneUtility.GetBuildIndexByScenePath method, which returns -1 if the scene is invalid or isn't in the build list.
.
 int sceneIndex = SceneUtility.GetBuildIndexByScenePath("Scenes/MyScene");
 if(sceneIndex >= 0) {
     SceneManager.LoadSceneAsync(sceneIndex);
 } else {
   // load menu 
 }
Your answer
 
 
             Follow this Question
Related Questions
Do I need a Loading Screen? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                