0

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?

Ben Arceneaux
  • 185
  • 1
  • 10
  • 1
    https://docs.unity3d.com/ScriptReference/Application-dataPath.html or https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html may help. – Retired Ninja Jun 18 '21 at 05:18

1 Answers1

0

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);
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Akhrorjon
  • 136
  • 9
  • I did figure this out but I no longer remember what the solution was... What is the protocol for handling these types of situations on SO? – Ben Arceneaux Sep 15 '21 at 15:29