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
- “Remove Unused Overrides” available on not loaded Scene and throws “ArgumentException: The scene is not loaded” warning
- Adaptive Probe Volume occlusion edge is calculated incorrectly when viewing probes near geometry edges
- Sampling a texture using an HLSL file throws shader errors and the code does not compile
- "Graphics.CopyTexture called with null source texture" error when Base Camera of an Overlay Camera is removed with DX11 Graphics API and Compatibility Mode enabled
- WebGL sends wrong value with large numbers when SendMessage function is used
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))