@@ -87,15 +87,12 @@ private static void EditorApplication_playModeStateChanged(PlayModeStateChange p
8787 /// </summary>
8888 private static void ScenesInBuildActiveSceneCheck ( )
8989 {
90- var scenesList = EditorBuildSettings . scenes . ToList ( ) ;
91- var activeScene = SceneManager . GetActiveScene ( ) ;
92- var isSceneInBuildSettings = scenesList . Count ( ( c ) => c . path == activeScene . path ) == 1 ;
9390#if UNITY_2023_1_OR_NEWER
9491 var networkManager = Object . FindFirstObjectByType < NetworkManager > ( ) ;
9592#else
9693 var networkManager = Object . FindObjectOfType < NetworkManager > ( ) ;
9794#endif
98- if ( ! isSceneInBuildSettings && networkManager != null )
95+ if ( ! IsActiveSceneInBuildList ( ) && networkManager != null )
9996 {
10097 if ( networkManager . NetworkConfig != null && networkManager . NetworkConfig . EnableSceneManagement )
10198 {
@@ -104,20 +101,47 @@ private static void ScenesInBuildActiveSceneCheck()
104101 $ "to synchronize to this scene unless it is added to the scenes in build list.\n \n Would you like to add it now?",
105102 "Yes" , "No - Continue" ) )
106103 {
107- // Double double check that the EditorBuildSettings.scenes has not changed already before adding
108- // this scene to the array (Parrel Sync issue)
109- scenesList = EditorBuildSettings . scenes . ToList ( ) ;
110- isSceneInBuildSettings = scenesList . Count ( ( c ) => c . path == activeScene . path ) == 1 ;
111- if ( ! isSceneInBuildSettings )
104+ // Double check that the scene hasn't already been added to the scenes in build list (potential issue with Parrel Sync)
105+ if ( ! IsActiveSceneInBuildList ( ) )
112106 {
113- scenesList . Add ( new EditorBuildSettingsScene ( activeScene . path , true ) ) ;
107+ var scenesList = EditorBuildSettings . scenes . ToList ( ) ;
108+ scenesList . Add ( new EditorBuildSettingsScene ( SceneManager . GetActiveScene ( ) . path , true ) ) ;
114109 EditorBuildSettings . scenes = scenesList . ToArray ( ) ;
115110 }
116111 }
117112 }
118113 }
119114 }
120115
116+ private static bool IsActiveSceneInBuildList ( )
117+ {
118+ var scenesList = EditorBuildSettings . scenes . ToList ( ) ;
119+ var activeScene = SceneManager . GetActiveScene ( ) ;
120+ var activeSceneAsset = AssetDatabase . LoadAssetAtPath < SceneAsset > ( activeScene . path ) ;
121+ var activeSceneHash = activeSceneAsset . GetHashCode ( ) ;
122+
123+ foreach ( var scene in scenesList )
124+ {
125+ var sceneAsset = AssetDatabase . LoadAssetAtPath < SceneAsset > ( scene . path ) ;
126+ var sceneAssetHash = sceneAsset . GetHashCode ( ) ;
127+ if ( activeSceneHash == sceneAssetHash )
128+ {
129+ return true ;
130+ }
131+ if ( sceneAsset . name == activeSceneAsset . name )
132+ {
133+ if ( scene . path != activeScene . path )
134+ {
135+ Debug . LogError ( $ "Active scene { activeScene . name } with path ({ activeScene . path } ) is potentially a duplicate of " +
136+ $ "scene { sceneAsset . name } with a path of ({ scene . path } )! Excluding from automatically adding to the scenes in build list!") ;
137+ // Exit as if it did find a perfect match
138+ return true ;
139+ }
140+ }
141+ }
142+ return false ;
143+ }
144+
121145 /// <summary>
122146 /// Invoked only when the hierarchy changes
123147 /// </summary>
0 commit comments