From b50706fa1390562fe10b88f021ece63d6bbaaeaa Mon Sep 17 00:00:00 2001 From: NoelStephensUnity Date: Wed, 18 Dec 2024 14:01:53 -0600 Subject: [PATCH 1/3] fix Prevent multiple scenes from being added to the scenes in build list. --- .../Editor/NetworkManagerHelper.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs index 3138369d57..2c656d37a0 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs @@ -104,8 +104,15 @@ private static void ScenesInBuildActiveSceneCheck() $"to synchronize to this scene unless it is added to the scenes in build list.\n\nWould you like to add it now?", "Yes", "No - Continue")) { - scenesList.Add(new EditorBuildSettingsScene(activeScene.path, true)); - EditorBuildSettings.scenes = scenesList.ToArray(); + // Double double check that the EditorBuildSettings.scenes has not changed already before adding + // this scene to the array (Parrel Sync issue) + scenesList = EditorBuildSettings.scenes.ToList(); + isSceneInBuildSettings = scenesList.Count((c) => c.path == activeScene.path) == 1; + if (!isSceneInBuildSettings) + { + scenesList.Add(new EditorBuildSettingsScene(activeScene.path, true)); + EditorBuildSettings.scenes = scenesList.ToArray(); + } } } } From fec4232c8bb69ccb6295d3449d2f00f3a2dcce20 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity Date: Wed, 18 Dec 2024 14:34:11 -0600 Subject: [PATCH 2/3] update Decided on a different approach to resolving this issue. --- .../Editor/NetworkManagerHelper.cs | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs index 2c656d37a0..f6d3fe5956 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs @@ -87,15 +87,12 @@ private static void EditorApplication_playModeStateChanged(PlayModeStateChange p /// private static void ScenesInBuildActiveSceneCheck() { - var scenesList = EditorBuildSettings.scenes.ToList(); - var activeScene = SceneManager.GetActiveScene(); - var isSceneInBuildSettings = scenesList.Count((c) => c.path == activeScene.path) == 1; #if UNITY_2023_1_OR_NEWER var networkManager = Object.FindFirstObjectByType(); #else var networkManager = Object.FindObjectOfType(); #endif - if (!isSceneInBuildSettings && networkManager != null) + if (!IsActiveSceneInBuildList() && networkManager != null) { if (networkManager.NetworkConfig != null && networkManager.NetworkConfig.EnableSceneManagement) { @@ -104,13 +101,11 @@ private static void ScenesInBuildActiveSceneCheck() $"to synchronize to this scene unless it is added to the scenes in build list.\n\nWould you like to add it now?", "Yes", "No - Continue")) { - // Double double check that the EditorBuildSettings.scenes has not changed already before adding - // this scene to the array (Parrel Sync issue) - scenesList = EditorBuildSettings.scenes.ToList(); - isSceneInBuildSettings = scenesList.Count((c) => c.path == activeScene.path) == 1; - if (!isSceneInBuildSettings) + // Double check that the scene hasn't already been added to the scenes in build list (potential issue with Parrel Sync) + if (!IsActiveSceneInBuildList()) { - scenesList.Add(new EditorBuildSettingsScene(activeScene.path, true)); + var scenesList = EditorBuildSettings.scenes.ToList(); + scenesList.Add(new EditorBuildSettingsScene(SceneManager.GetActiveScene().path, true)); EditorBuildSettings.scenes = scenesList.ToArray(); } } @@ -118,6 +113,35 @@ private static void ScenesInBuildActiveSceneCheck() } } + private static bool IsActiveSceneInBuildList() + { + var scenesList = EditorBuildSettings.scenes.ToList(); + var activeScene = SceneManager.GetActiveScene(); + var activeSceneAsset = AssetDatabase.LoadAssetAtPath(activeScene.path); + var activeSceneHash = activeSceneAsset.GetHashCode(); + + foreach (var scene in scenesList) + { + var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); + var sceneAssetHash = sceneAsset.GetHashCode(); + if (activeSceneHash == sceneAssetHash) + { + return true; + } + if (sceneAsset.name == activeSceneAsset.name) + { + if (scene.path != activeScene.path) + { + Debug.LogError($"Active scene {activeScene.name} with path ({activeScene.path}) is potentially a duplicate of " + + $"scene {sceneAsset.name} with a path of ({scene.path})! Excluding from automatically adding to the scenes in build list!"); + // Exit as if it did find a perfect match + return true; + } + } + } + return false; + } + /// /// Invoked only when the hierarchy changes /// From 6967621f22bbeb3f26c5ceb10befd1e227831785 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity Date: Wed, 18 Dec 2024 15:12:34 -0600 Subject: [PATCH 3/3] fix Failing on hash mismatch. --- .../Editor/NetworkManagerHelper.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs index f6d3fe5956..b6a8bdc814 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs @@ -134,9 +134,14 @@ private static bool IsActiveSceneInBuildList() { Debug.LogError($"Active scene {activeScene.name} with path ({activeScene.path}) is potentially a duplicate of " + $"scene {sceneAsset.name} with a path of ({scene.path})! Excluding from automatically adding to the scenes in build list!"); - // Exit as if it did find a perfect match - return true; } + else + { + Debug.LogError($"Active scene {activeScene.name} was found but the active scene asset hash value ({activeSceneHash}) was " + + $"not the same as the the one in the scenes in build list ({sceneAssetHash})! Excluding from automatically adding to the scenes in build list!"); + } + // Exit as if it did find a perfect match + return true; } } return false;