Addressables.LoadSceneAsync affects Execution Order of cross-scene coroutines

I use Addressables.LoadSceneAsync() to load all scenes in our game. I’ve found that doing so completely disrupts Script Execution Order for coroutines (and maybe Update too, but I haven’t tested).

No matter how high a cross-scene coroutine’s priority is, it will run AFTER the coroutines in a new scene being loaded by addressables.

I tried experimenting with the “priority” parameter of LoadSceneAsync (even though I know that’s for threads) and that didn’t help.

Using addressables to load scenes just breaks the order completely. I filed a bug too, but I wanted to post about it here in case the devs had some pointers on how to work around the issue.

bump

bump

Hi @VoodooDetective I took a look at your ticket submission, and seems like it’s missing a project zip? I only see the log files attached to it.

LoadSceneAsync does use multiple threads:
“Asynchronous load functions that load objects (Resources.LoadAsync, AssetBundle.LoadAssetAsync, AssetBundle.LoadAllAssetAsync), scenes (SceneManager.LoadSceneAsync) do data read and deserealization on a separate background loading thread and object integration on a main thread.”

I’m guessing what’s happening here is that LoadSceneAsync is blocking the main thread, preventing coroutines from running in the order that you expect. It would be better practice to avoid running any coroutines until after LoadSceneAsync is done.

The “priority” parameter of LoadSceneAsync correlates to the AsyncOperation.priority field Unity - Scripting API: AsyncOperation.priority

This sounds similar to issues I’ve had before. Check here LoadSceneAsync() callback not firing until a frame late [bug?]

Ah, I see. It spend a few days on this and found a way to work around it (very specific to our project). It’d be super helpful if this could be documented somewhere.

1 Like

Yes we can add a warning about using coroutines with LoadSceneAsync in the docs

1 Like