Search Issue Tracker
By Design
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
- UnityYamlMerge.exe doesn't correctly handle merge conflicts in modified properties on a prefab variant
- Inconsistent color scheme in "Details" section of "Select Presets" inspector window
- Crash on __pthread_kill when launching Editor via command-line with "-disableManagedDebugger" argument
- [VFX] Deleting “New Group Node” name doesn’t allow to type or add new name
- [VFX] Creating a long Group Node name breaks nodes boarders
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))