Version: 2022.3
LanguageEnglish
  • C#

Application.CanStreamedLevelBeLoaded

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static bool CanStreamedLevelBeLoaded(int levelIndex);

Description

Checks if the built scene can be loaded.

Test if a scene with the provided index exists in the Player build. Returns true if the index value is greater than or equal to zero, and less than SceneManager.sceneCountInBuildSettings.

// Check if level at index 1 can be loaded.
// If it can be loaded then load it.
using System;
using UnityEngine;

public class SampleBehaviour : MonoBehaviour { void Start() { if (Application.CanStreamedLevelBeLoaded(1)) { Application.LoadLevel(1); } } }

Declaration

public static bool CanStreamedLevelBeLoaded(string levelName);

Description

Checks if the built scene can be loaded.

Verify if the named scene exists in either the Player build or currently loaded AssetBundles. Additional resources: SceneManager

// Check if "Level1" can be loaded, if it can be loaded then load it.
using System;
using UnityEngine;

public class SampleBehaviour : MonoBehaviour { void Start() { if (Application.CanStreamedLevelBeLoaded("Level1")) { Application.LoadLevel("Level1"); } } }