Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CanStreamedLevelBeLoaded

Checks if the built scene can be loaded.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

CanStreamedLevelBeLoaded(int)

Checks if the built scene can be loaded.
public static bool CanStreamedLevelBeLoaded(int levelIndex)

Parameters

levelIndex

Returns

Type

Description

bool

Remarks

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.

Examples

// 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); } }}

CanStreamedLevelBeLoaded(string)

Checks if the built scene can be loaded.
public static bool CanStreamedLevelBeLoaded(string levelName)

Parameters

levelName

Returns

Type

Description

bool

Remarks

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

Examples

// 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"); } }}