Search Issue Tracker
By Design
Votes
0
Found in
5.6.0b11
Issue ID
896474
Regression
No
SceneManager.GetSceneByBuildIndex().name returns an empty string if scene is not loaded
Reproduction steps:
1. Open the attached project and run any scene
2. See, that .GetSceneByBuildIndex().name returns valid name only for the scene which is loaded
3. You can click "Load next scene" to verify, that it happens on every scene
This bug makes it difficult to retreive all the scene names during runtime
Comments (14)
-
kloot
Jun 29, 2021 14:30
If this is by design... How intuitive would you say that design is? :)
-
Mads-Nyholm
Nov 16, 2020 08:47
This is by design because the SceneManager manages scenes that have been loaded so if it hasn't been loaded yet you cannot query any information from the returned Scene struct. Try checking the scene.IsValid() method before querying any info.
SOLUTION:
You should use SceneUtility.GetScenePathByBuildIndex() instead as this will work regardless of the scene being loaded or not. If you only need the name you can get that from the path. -
TheProcessor
Jul 14, 2020 20:30
Please fix it!
-
zhuchun
Jun 12, 2020 08:00
When Unity insisted that it's by design, it's a design flaw
-
deeprest
Apr 01, 2020 09:58
2019.3.6f1 still has this error. THIS SHOULD NOT BE BY DESIGN.
SceneManager.GetSceneByBuildIndex() should take a build index and return a Scene struct.
I think most folks try to get the scene struct this way IN ORDER TO THEN LOAD THE SCENE.
If it only returns LOADED scenes BY DESIGN, call the function GetLoadedSceneByBuildIndex(),
and then provide us with a function that returns a valid scene struct from a scene in the build menu. -
lassfar
Mar 26, 2020 12:26
Unity version 2019.1.3f1
The error :
"NullReferenceException: Object reference not set to an instance of an object
LevelManager.NextLevelLoader () (at Assets/Scripts/LevelManager.cs:94) //My Script
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:66)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:108)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()".My respectful greetings to Unity Technologies Team for its efforts
-
ghostravenstorm
Mar 01, 2020 01:22
2019.3.2f1 still has this problem.
-
unity_YkF-_UDlrzm5Nw
Sep 26, 2018 10:32
2018.4.11f1 Still has this error.
-
Estellise-Yukihime
Aug 18, 2018 14:35
2017.4.1f1 also have this error.
-
jonnieballs
Apr 16, 2018 13:34
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on RaiseException when opening a specific project
- DownloadHandlerScript.CompleteContent is called twice when building for WebGL
- Scene view has Y coordinates of the Screen Position node flipped when some of the URP features are disabled
- Volumetric fog shader variants are missing from build when "Strict Shader Variant Matching" is disabled
- Unnecessary modifications clutter the Scene when using a RectTransform driven by a LayoutGroup in a Prefab
Resolution Note:
This is by design because the SceneManager only manages scenes that have been loaded so if it hasn't been loaded yet you cannot query any information from the returned Scene struct. Try checking the scene.IsValid() method before querying any info.
SOLUTION:
You should use SceneUtility.GetScenePathByBuildIndex() instead.
Note you can have scenes named the same at different paths so the path is better to use in general.