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
- Crash on ScheduleGenerateTilingShape when modifying PolygonCollider2D path count and setting path vertices
- Crash when a scene is created with LocalPhysicsMode::Physics3D
- [HDRP] Light doesn't bounce off terrains
- Unity Hub opens instead of the Unity Editor when launching a project from a Windows command line if a backslash is added to the end of the project path
- "ParseErrorException" is thrown when parsing a float with a very small value from JSON
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))