Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question AssetBundles loaded except one, Maybe memoryBudgetKB issue ??

Discussion in 'Scripting' started by Insightful_Designer, Mar 13, 2023.

  1. Insightful_Designer

    Insightful_Designer

    Joined:
    Jul 28, 2022
    Posts:
    19
    I receive a byte Array (bufferArray) through TcpClient in Unity 2020.3 .
    Then I load successfully the byte Arrays to AssetBundles and then to prefabs.

    for example
    in the Code below the ContentPrefab_restaurant is loaded successfully, aka the code works.
    But the ContentPrefab_supermarket is not loaded. It is not null.

    Size of byteArray of restaurant is 556 384 bytes, and all the other file sizes < 1 MB
    and of supermarket is 1_058_912 bytes > 1 MB.

    The size of supermarket byte Array is the only one that is bigger than
    AssetBundle.memoryBudgetKB = 1 MB default value,
    as it says here
    https://docs.unity3d.com/ScriptReference/AssetBundle-memoryBudgetKB.html

    I added the next line
    AssetBundle.memoryBudgetKB = 1_058_912;

    Code (csharp):
    1.  
    2.  case "restaurant":      // 4 restaurant prefab
    3.     if (ContentPrefab_restaurant == null)
    4.     {
    5.         MyAssetBundleRequest = AssetBundle.LoadFromMemoryAsync(bufferArray);
    6.         while (!MyAssetBundleRequest.isDone) await Task.Yield();
    7.         AssetBundle_restaurant = MyAssetBundleRequest.assetBundle;
    8.         if (AssetBundle_restaurant != null)
    9.         {
    10.             assetLoadRequest = AssetBundle_restaurant.LoadAssetAsync<GameObject>(AssetBundle_restaurant.GetAllAssetNames()[0]);
    11.             while (!assetLoadRequest.isDone) await Task.Yield();
    12.             ContentPrefab_restaurant = assetLoadRequest.asset as GameObject;
    13.         }
    14.     }
    15.     break;
    16. case "supermarket":      // 5 market prefab
    17.                          //case "grocery_or_supermarket":
    18.     AssetBundle.memoryBudgetKB = 1_058_912;
    19.     if (ContentPrefab_supermarket == null)
    20.     {
    21.         MyAssetBundleRequest = AssetBundle.LoadFromMemoryAsync(bufferArray);
    22.         while (!MyAssetBundleRequest.isDone) await Task.Yield();
    23.         AssetBundle_supermarket = MyAssetBundleRequest.assetBundle;
    24.         if (AssetBundle_supermarket != null)
    25.         {
    26.             assetLoadRequest = AssetBundle_supermarket.LoadAssetAsync<GameObject>(AssetBundle_supermarket.GetAllAssetNames()[0]);
    27.             while (!assetLoadRequest.isDone) await Task.Yield();
    28.             ContentPrefab_supermarket = assetLoadRequest.asset as GameObject;
    29.         }
    30.     }
    31.     break;
    32.  
    33.