Why is loading local bundles on Android still so slow (like really slow) via AssetBundle.LoadFromFileAsync ? When I switch to load via UnityWebRequest (“Use UnityWebRequest for Local Asset Bundle” option from settings) the speed process is much faster than AssetBundle , but the **problem is that the bundles are duplicated(**AssetBundle Loading | Addressables | 1.18.19), so in my case the game becomes almost twice in size .
Also , why is this system seen as a replacement for the old
Resource system when obviously has a major problem and it’s not emphasized anywhere (I’m talking about Android) ?
Since there will be no fix for this anytime soon , I advise to everyone who has the same problem to move back to Resources and drop out completely if possible Addressable , but keep the flow to be ready when this bug is fixed , here it’s quick code which wrap Resources and Addressable into one , so when it’s ready you’ve just to modify the call .
using System;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Object = UnityEngine.Object;
namespace General
{
public static class ResourceBundle
{
public static BundleAsyncOp<T> ResourceLoad<T>(string key , bool isLoad) where T : Object
{
var op = Resources.LoadAsync<T>(key);
return new BundleAsyncOp<T>(op);
}
public static BundleAsyncOp<T> AddressableLoad<T>(string key) where T : Object
{
var op = Addressables.LoadAssetAsync<T>(key);
return new BundleAsyncOp<T>(op , true);
}
public static BundleAsyncOp<T> AddressableInstantiate<T>(string key) where T : Object
{
var op = Addressables.LoadAssetAsync<T>(key);
return new BundleAsyncOp<T>(op , false);
}
}
public class BundleAsyncOp<T> where T : Object
{
/// <summary>
/// Specific for addressable , IsLoad asset or instantiate gameobject
/// </summary>
private readonly bool IsLoad;
private readonly bool IsAddressable;
private readonly ResourceRequest ResourceRequest;
private readonly AsyncOperationHandle<T> AddressableOperation;
public Action<BundleAsyncOp<T>> Completed;
public bool IsDone => IsAddressable ? AddressableOperation.IsDone : ResourceRequest.isDone;
public T Result
{
get
{
if (IsAddressable) return AddressableOperation.Result;
return (T) ResourceRequest.asset;
}
}
public BundleAsyncOp(AsyncOperationHandle<T> addressableOperation, bool isLoad)
{
IsAddressable = true;
AddressableOperation = addressableOperation;
IsLoad = isLoad;
}
public BundleAsyncOp( ResourceRequest resourceRequest)
{
IsAddressable = false;
IsLoad = false;
ResourceRequest = resourceRequest;
ResourceRequest.completed += operation =>
{
Completed?.Invoke(this);
};
}
}
}