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

Resolved How to access multiple assets from a Asset Bundle

Discussion in 'Asset Bundles' started by RafaelGomes00, Dec 21, 2022.

  1. RafaelGomes00

    RafaelGomes00

    Joined:
    Aug 13, 2020
    Posts:
    73
    Hello, I'm having a problem to load multiple assets from a single asset bundle.
    Here's the code I use to create the asset bundles:

    Code (CSharp):
    1. static void BuildAllAssetBundles()
    2.     {
    3.         if (Directory.Exists(assetBundleDirectory))
    4.             Directory.Delete(assetBundleDirectory, true);
    5.  
    6.         Directory.CreateDirectory(assetBundleDirectory);
    7.  
    8.         AssetBundleManifest iosManifest = BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.iOS);
    9.         Debug.Log("IOS bundle created...");
    10.         AppendPlatformToFileName("ios");
    11.  
    12.         AssetBundleManifest androidManifest = BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.Android);
    13.         Debug.Log("Android bundle created...");
    14.         AppendPlatformToFileName("android");
    15.  
    16.         AssetDatabase.Refresh();
    17.         Debug.Log("Process complete!");
    18.     }
    The generated asset bundle:
    upload_2022-12-21_13-58-29.png

    It seems everything works fine, but when I try to get all the asset paths, I get only the first one "Mapa".
    But, if "Mapa" is removed from the asset bundle, the asset "SceneSettings" is returned.
    So, it seems that only the first asset from the Asset Bundle is returned.

    Code to get all asset names:
    Code (CSharp):
    1. foreach(string name in bundle.GetAllAssetNames())
    2. {
    3.    Debug.Log(name);
    4. }
    It returns:
    "assets/lobby/mapa.prefab"

    I expected to return:
    "assets/lobby/mapa.prefab"
    "assets/lobby/scenesettings.asset"
     
    Last edited: Dec 21, 2022
  2. RafaelGomes00

    RafaelGomes00

    Joined:
    Aug 13, 2020
    Posts:
    73
    Fixed.
    The problem seems to be because i was using another unity project to export my bundles.
    When I did it on the main project it worked.