I create AssetBundle from memory (array of bytes):
class Loader
{
AssetBundleCreateRequest createRequest;
void enter(byte[] bundleBytes)
{
createRequest = AssetBundle.CreateFromMemory(bundleBytes);
}
void update()
{
if (createRequest != null && createRequest.isDone)
{
//do the job
}
}
As you can see I use polling to check request state and don’t use coroutines/yield. CreateFromMemory() method according to Unity documentation is asynchronous. But according to profiler it behaves exactly like synchronous method: in place when it’s called game literally freezes, frame takes >1 second to complete and 99% of time is taken exactly by AssetBundle.CreateFromMemory() method. I compared this to
CreateFromMemoryImmediate() - time is almost the same.
Please, help!
EDIT1: Read documentation one more time. It seems to be a little bit misleading. Maybe what they mean by “asynchronous” - it’s only decompression on separate thread (when asset bundle is compressed)? Seems like actual asset bundle creation is really synchronous anyway. Will try to use asynchronous delegates w/ CreateFromMemoryImmediate(). I know that Unity API not thread safe but have no other choice.
EDIT2: With async delegate I get error (as expected): “CreateFromMemoryImmediate() can only be called from the main thread.” I’m really frustrated. Seems that asset bundles don’t provide any way to create them asynchronously, it will always result in “stop-the-world” behavior.