Yield return in AssetBundle.CreateFromMemory

1k Views Asked by At

As documentation says IEnumerator methods are executed like thread, but I'm confused why

AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.CreateFromMemory(ByteArray);
yield return assetBundleCreateRequest;

freezes my game for 2 seconds. Can anybody explain?

1

There are 1 best solutions below

3
On

Well it freezes for 2 seconds because that is what you are actually requesting with your yield return assetBundleCreateRequest

Asynchronous operation coroutine.

You can yield until asynchronous operation continues, or manually check whether it's done (isDone) or progress (progress). AsyncOperation

So right now you are requesting your coroutine to wait till your assetbundlecreaterequest is done.

For manually checking wheter the function is done, without having to freeze your application would be using the isdone or progress command instead

If you need further clarification feel free to comment.

Edit

Sample of using isdone

AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
while (!acr.isDone)
{
    yield;
}
AssetBundle bundle = acr.assetBundle;