0
votes

After struggling to load assets from resources (I still haven't figured out why this wouldn't work actually) I was able to finally load assets during runtime after packing them into AssetBundles using the following code:

var myBundle = AssetBundle.LoadFromFile("Assets/AssetBundles/soundanchors");
  if (myBundle == null)
  {
     Debug.Log("Failed to load assets from bundle at Assets/AssetBundles");
  }
  else
  {
     Debug.Log("Successfully loaded sound anchors from Assets/AssetBundles");
     soundAnchors = myBundle.LoadAllAssets();
     AddAnchorsToGrid();
  }

The code works fine when I build and run the project on OS X. However, once I build the project and run it on an IOS device I am no longer seeing the asset bundles load.

I'm assuming this is because the path to where the bundles are saved is different on IOS but I'm having trouble locating where I should be looking for them.

As you can see from the code, the location of the bundles in my Assets folder is here: "Assets/AssetBundles/soundanchors"

How does Unity handle the asset paths on IOS? Is there some constant in the Unity API that holds the default IOS path prefix?

1

1 Answers

0
votes

As far as I remember for IOS, you have to create folder named StreamingAssets in Assets like "Assets/StreamingAssets" and put your bundles inside of it. You can load your assetsbunles like this:

void Start()
{
    var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle"));
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }

    var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject");
    Instantiate(prefab);

    myLoadedAssetBundle.Unload(false);
}