Fix sceneID mismatch bug between build (buildIndex=-1) and editor (buildIndex=0) for projects where the scene was not added to build settings list

This commit is contained in:
vis2k 2019-03-13 18:36:20 +01:00
parent 8642056f21
commit 62fc738673

View File

@ -284,7 +284,13 @@ void AssignSceneID()
public void SetSceneIdSceneIndexByteInternal()
{
// get build index
byte buildIndex = (byte)gameObject.scene.buildIndex;
// -> if the scene is not in build settings, then a build would
// have buildIndex '-1', but pressing Play in the Editor would
// have a buildIndex '0', which would always get sceneIds out of
// sync if we didn't add the scene to build settings.
// -> let's always use at least '0', which is what unity Editor does
// internally as it seems.
byte buildIndex = (byte)Mathf.Max(gameObject.scene.buildIndex, 0);
// OR into scene id
m_SceneId = (m_SceneId & 0x00FFFFFF) | (uint)(buildIndex << 24);