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
- URP Realtime reflection probes do not update when RenderProbe() is being called once per second
- Addressable terrain shader variants are stripped from the Player
- [iOS] Debug.Log() appears as <private> in Console app
- UI stays in the background when it is disabled in simulator
- A wrong log file is attached when project is launched with a "-logFile" command line argument
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))