How to force-test LoadSceneAsync network errors and recover?

We badly need to be able test and develop a recovery method for Addressables loading errors on iOS because they have been rare in the wild, in Unity 2021.3.16f1 and fetching our scenes from AWS. When there are network errors and the scenes don’t load fully, the game is left in an unacceptable state!

We use Addressables.LoadSceneAsync to load scenes additively on top of a base scene. We have implemented the ResourceManager.ExceptionHandler and are catching problems when they happen, but having difficulty figuring out how to recover from a failed loads. We cannot reproduce problems in the editor.

If any one can point us to the right information for dealing with this it is much appreciated:

  1. how can we simulate a network disruption to Addressables.LoadSceneAsync in the editor to so that we can debug what is going on and come up with working recovery strategy?

  2. What happens if Addressables.LoadSceneAsync fails halfway though? Because we seem to be left with a black screen on top of our base scene. So its like the scene partly loaded. How can we get rid of that and return to our previous state before the scene was partially loaded? Can we call UnloadAsync if we don’t have a network connection???

Thanks again for any help!

[Solved] Set up the Addressables Local Hosting server, follow the documentation, and what is not in the documentation: Set the Play Mode Script to “Use Existing Build”

For 1: There is a Hosting Service in the Addressables package. When I was integrating the Addressables to our project, I modified it to simulate the bad network situation in Editor.

1 Like

thank you so much for your reply! Sorry, but I’m still relatively new to Addressables, and I did not know about this feature.

What about the Hosting Service did you modify?

Ok, I got the hosting service set up as per the docs (thanks @Alan-Liu ), and as also in accord with an official Unity tutorial, but the assets load so fast it is hard to tell anything - I see the host setup has a an Upload Speed field that I assume is a throttle… for upload speed? But no control over download speed…huh?

I don’t see how this gets me closer to being able to induce an Addressables loading error if I cannot slow the download speed down. Putting a breakpoint into the coroutine loop that checks the loading progress and waiting for a minute or two before continuing does not cause an error.

What gives?

First, the upload speed is for controlling download speed. In case you’re using latest Addressables(e.g. 1.21.9 or 1.21.10), the unit of the speed is wrong, should be B/s, not KB/s. Earlier version may be correct.

For simulating the bad network situation, I moved the Addressables package to Packages folder, so I can modify the code of it (Doc link). Specifically, I modified the code of HttpHostingService.FileUploadOperation.

For example, when I wanted to test if the behaviour of retrying downloading is expected, I modified FileUploadOperation.Update to not send the data for a specific asset bundle for the first time.

1 Like

@Alan-Liu you literally saved me from hours of pain! Because finding documentation or discussion about this topic is near zero, and chat gpt - the new new thing - was worse than no help at all. (It was like, why did I bother to ask you this 5 different ways.)

I thought there was an easy way out: say, slow it down enough that I could mosey over and turn the Local Host off or something. We have some pretty massive scenes that we’re loading should not go that fast…

However the Upload Speed whatever does nothing on my system - perhaps it is broken in the Apple Silicon editor I am running. Has zero effect no matter what number I put in there. it seems to be stuck on blazing-fast.

And there is zero documentation that Speed parameter in all the latest version official docs and the tutorial .

I guess I find it hard to believe there is such a dearth of information on this topic, because network glitches do happen - such as “Lost Server Connection” - and how the hell are people recovering from that without a testing mechanism to see what state the game is in?

I feel like there is something fundamental I’m missing - maybe it is it too simple? Perhaps on error I just need to release the handle of whatever Scene asset that was in progress when ResourceManager.ExceptionHandler caught the exception? That doesn’t seem to be documented anywhere if that is the case…

And anyway doesn’t seem possible either, because the handle returned with the LoadSceneAsync call is assigned in a coroutine, and you’d have to access that handle through the ExceptionHandle event listener? If there are multiple async calls running and throwing exceptions, how are you going to know which asset to release? - sounds like the only way is to chain asyc loads one after the other…

Thank you so much again for sharing your knowledge!

Hey all, how much hair do you have to pull out to get the Local Host to actually work in the editor? (rhetorical question) If you don’t want to pull your hair out, just poke yourself in the face with a sharp stick about 50 times.

For anyone reading this, here is what you have to do to get the Local Hosting feature of Addressables to serve local files over the network:

If you follow the documentation, see the previous replies in this thread, everything will be set up properly, but it omits the final critical step: Set the Play Mode Script to “Use Existing Build”

What is worse, the official Unity Local Hosting tutorial is dead wrong - it states to set Play Mode to “Use Asset database” - If you do that, Local Host is completely ignored.

Now I can slow the upload speed way down and while the scene asset is downloading, turn the server off to trigger an exception - and it triggers more than one. Now the fun begins!