Does AssetBundle.LoadAsset block main thread?

So, we are having “GameObject references runtime script in scene file. Fixing!” bug when using AssetBundle.LoadAssetAsync. Using AssetBundle.LoadAsset fixes it.

We are running LoadAsset in a separate corotinue, however, the documentation isn’t very clean on whether LoadAsset blocks the main UI thread if it’s ran on a separate coroutine. Anyone have any information about this? Thanks.

You need to use LoadAsset Async to load it in the background and be able to wait for it in a co-routine.

So are there any difference between using LoadAssetAsync in a coroutine and wait for it vs using LoadAsset in a Coroutine?

Yes, LoadAssetAsync is Asynchronous.

LoadAsset blocks.

Using LoadAsset in a coroutine won’t get you anything over just calling it normally. Putting something in a coroutine doesn’t automatically make it asynchronous and coroutines still execute on the main thread. They simply provide you the opportunity to spread the execution of your code out over multiple frames.

AssetBundle.LoadFromFileAsync called via Coroutine but still using the main thread. This leads to freezing UI issue when loading a large asset bundle file. I wonder if we can call new thread (non-main thread) to use AssetBundle.LoadFromFileAsync?

You cannot use Unity API methods across multiple threads- they aren’t thread-safe.

Is there anyway to solve the issue of block UI when loading the asset bundle from file?

Using Async in a coroutine is the closest you’re going to get.

Hm, Async is still in main thread with blocking UI. It seems like the only solution is to make multiple small asset bundle files :slight_smile: