UnityEngine.SceneManagement.SceneManager.GetSceneByName C# (CSharp) Method

GetSceneByName() public static method

Searches through the scenes added to the SceneManager for a scene with the given name.

public static GetSceneByName ( string name ) : Scene
name string Name of scene to find.
return Scene
        public static Scene GetSceneByName(string name)
        {
            Scene scene;
            INTERNAL_CALL_GetSceneByName(name, out scene);
            return scene;
        }

Usage Example

        private static IEnumerator LoadInternal(LoadContext context)
        {
            if (context == null)
            {
                yield break;
            }

            var scene = UnitySceneManager.GetSceneByName(context.NextScene.Name);

            if (!scene.isLoaded)
            {
                yield return(UnitySceneManager.LoadSceneAsync(context.NextScene.Name, LoadSceneMode.Additive));
            }
            UnitySceneManager.SetActiveScene(UnitySceneManager.GetSceneByName(context.NextScene.Name));

            var sceneContext = FindSceneContext(context.NextScene.Name);

            if (sceneContext == null)
            {
                yield break;
            }

            yield return(new WaitUntil(() => sceneContext.Initialized));

            var sceneSettings = sceneContext.Container.TryResolve <SceneSettings>();

            if (sceneSettings != null)
            {
                sceneSettings.Subs.ForEach(x => context.AddAdditiveScene(x));
            }
            context.NextScene.Lifecycles = sceneContext.Container.ResolveAll <ISceneLifecycle>();
        }
All Usage Examples Of UnityEngine.SceneManagement.SceneManager::GetSceneByName