SceneManager.LoadScene() doesn't raise an exception on a bad scene name

Hi there,

I’m working on a low level game framework and have an odd problem with SceneManager.LoadScene().
If you pass it an invalid scene name an error gets generated in the editor event log, but no exception gets raise on the code side.

As this method returns void it’s hard to marshal what happens on a bad load attempt and take appropriate action.

Could anyone confirm this behaviour and would it be worth raising an “issue”?

A.

I do not know about try and catch an error in the script (I do not use it in Unity), but you can check whether the scene is valid or not at the scene with given name using the build in method.

SceneManager.GetSceneByName(sceneName).IsValid(); // False - the scene is not valid, true - it is valid.
3 Likes