Prevent error from not finding Server

Any suggestions on how to avoid a null reference?

A little more context and info would be helpful here @faolad .

Does this help? Unity - Manual: Null Reference Exceptions

I have tried using Try/Catch Blocks but can’t manage to make it work. I’m trying to prevent errors in-game by avoiding getting Exception error while using “Addressables.LoadSceneAsync” in case the RemoteLoadServer is down. But so far I haven’t been able to do so. The issue is that I keep getting “couldn’t be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.”

What I want to achieve is:

Adressables.LoadSceneAsync(sceneName, activateOnLoad: false).Completed += OnCompleted;

void OnCompleted(AsyncOperationHandle<SceneInstance> handle)
        {
            var sceneInstance = handle.Result;

            if (sceneInstance Good)
            {
                // Activate the scene.
                sceneInstance.Activate();
            }
            else//Server is offline/bad
            {
                Addressables.LoadSceneAsync("DummyScene", LoadSceneMode.Single);
            }
        }

So if the scene you are trying to load and download cant be, load a functional instead. I think it has something to do with addressables not able to verify a scene before loading it.

1 Like

The only thing that works is this hack, I hope Unity people make a workaround this…

Application.logMessageReceived += HandleLog;
void HandleLog (string log, string stackTrace, LogType type) {
   if (type == LogType.Error) {
       if (log.Contains("couldn't be loaded because it has not been added to the build settings"))
           SceneLoadFailed();
        }
}