Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Can't Load Assetbundle On iOS

Discussion in 'iOS and tvOS' started by cbunseng, Feb 24, 2012.

  1. cbunseng

    cbunseng

    Joined:
    Feb 24, 2012
    Posts:
    1
    Hi all.

    i was trying my best not too ask question. but i could not get it to work. been working on asset bundle for sometime now. i was able to create the asset bundle and it work perfectly with osx and web. but i can't get it to load on on the iPhone. look around for the answer, and here what i found. http://www.chrisdanielson.com/2011/05/03/unity3d-file-assetbundles-on-the-iphone/

    but it does not seem to load in local and web. and i wondering if you guys let me know what did i do wrong. i know apple stick us from assess var/mobile.. so is there any way i can make it work?

    P.s. i already build the asset success and i try to place it in Xcode. thank in advance.

    Thank in advance.

    Here my loading code
    using System;
    using UnityEngine;
    using System.Collections;

    public class Example : MonoBehaviour {
    private WWW www;
    private AssetBundleRequest gameObjectRequest;
    // Use this for initialization
    IEnumerator Start () {
    //TODO: change the name of the file below!!!
    String strPath = "file://" + Application.dataPath + "/../iphone-prefab-sphere.assetbundle";
    Debug.Log(strPath);
    www = new WWW(strPath);
    yield return www;
    /* TODO: change the name "Box" to match the name of your prefab that you compiled into the assetbundle on step 1. */

    //AssetBundleRequest request = www.assetBundle.LoadAsync("Sphere", typeof(GameObject));
    yield return request;
    Instantiate(request.asset, new Vector3(3f, 0f, 0f), Quaternion.identity);
    Instantiate(request.asset, new Vector3(0f, 0f, 0f), Quaternion.identity);
    Instantiate(request.asset, new Vector3(-3f, 0f, 0f), Quaternion.identity);
    www.assetBundle.Unload(true);
    }
    void Update() { }
    }
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you likely don't build the asset bundle for the iOS platform.
    Asset bundles only work for the platform they were built and only on the unity version they were built with.

    Also keep in mind that you must own Unity iOS Pro to use Asset Bundles.

    PS: The path is incorrect for granted, on iOS the file will NEVER be there.
    if you download it from the web, instead use WWW.LoadFromCacheOrDownload which significantly reduces the load times as it stores the cached asset bundles uncompressed
     
  3. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
  4. Fehr

    Fehr

    Joined:
    Mar 3, 2011
    Posts:
    23
    I found this really helpful, hopefully others looking here will too:

    http://www.chrisdanielson.com/2011/05/03/unity3d-file-assetbundles-on-the-iphone/

    It is possible to get access to files in the XCode project by first getting Asset.DataPath, and traversing the directory one level to files within the root of the xcode project, eg:

    "file://" + Application.dataPath + "/../Packaged_iOS/" + bundleGroupNames[type] + ".unity3d";