Search Issue Tracker
By Design
By Design in 2023.2.X
Votes
0
Found in
2020.3.48f1
2021.3.26f1
2022.3.0f1
2023.1.0b18
2023.2.0a16
Issue ID
UUM-36826
Regression
No
”-1” is returned when using “buildIndex” for not active scenes that are in the "Scenes In Build" list
How to reproduce:
1. Open the user’s attached “sceneIndexBug.zip” project
2. Enter Play Mode and observe the text in the Game window
Expected result: Text is: “0 1 2”
Actual result: Text is: “0 -1 -1”
Reproducible with: 2020.3.48f1, 2021.3.26f1, 2022.3.0f1, 2023.1.0b18, 2023.2.0a16
Reproduced on: macOS 13.2.1 (Intel)
Note: reproducible in the Editor and in the Standalone Player (macOS)
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
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
Resolution Note:
SceneManager only manages loaded Scenes. So SceneManager.GetSceneByName() will return an invalid Scene for Scenes that are not loaded, in your example SampleScene2 and SampleScene3 (https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetSceneByName.html). This in turn causes Scene.buildIndex to be invalid (-1).
For general buildsettings info, you can use the SceneUtility methods. To get the buildIndex of a SceneAsset, you could use:
SceneUtility.GetBuildIndexByScenePath(AssetDatabase.GetAssetOrScenePath(sceneAsset))
Resolution Note (2023.2.X):
SceneManager only manages loaded Scenes. So SceneManager.GetSceneByName() will return an invalid Scene for Scenes that are not loaded, in your example SampleScene2 and SampleScene3 (https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.GetSceneByName.html). This in turn causes Scene.buildIndex to be invalid (-1).
For general buildsettings info, you can use the SceneUtility methods. To get the buildIndex of a SceneAsset, you could use:
SceneUtility.GetBuildIndexByScenePath(AssetDatabase.GetAssetOrScenePath(sceneAsset))