Skip to content

Commit 17f3f51

Browse files
committed
Add warning before loading a scene which is not added to build settings
1 parent 2684091 commit 17f3f51

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Packages/com.chark.scriptable-scenes/Runtime/ScriptableScene.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,22 @@ AsyncOperation StartLoadSceneOperation()
279279
var parameters = new LoadSceneParameters(LoadSceneMode.Additive);
280280

281281
#if UNITY_EDITOR
282-
// Allow to load scenes which are not added to Build Settings (Editor only).
283-
return UnityEditor.SceneManagement.EditorSceneManager
284-
.LoadSceneAsyncInPlayMode(scenePath, parameters);
282+
var buildIndex = SceneUtility.GetBuildIndexByScenePath(scenePath);
283+
if (buildIndex < 0)
284+
{
285+
Debug.LogWarning(
286+
$""
287+
+ $"Loading scene '{scenePath}' which is not added to build settings, make "
288+
+ $"sure to add it before making the final build or it wont load!",
289+
this
290+
);
291+
292+
// Allow to load scenes which are not added to Build Settings (Editor only).
293+
return UnityEditor.SceneManagement.EditorSceneManager
294+
.LoadSceneAsyncInPlayMode(scenePath, parameters);
295+
}
296+
297+
return SceneManager.LoadSceneAsync(scenePath, parameters);
285298
#else
286299
return SceneManager.LoadSceneAsync(scenePath, parameters);
287300
#endif

0 commit comments

Comments
 (0)