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

simple asset bundle test not working please help

Discussion in 'Asset Bundles' started by Amitr, Nov 23, 2017.

  1. Amitr

    Amitr

    Joined:
    Mar 3, 2013
    Posts:
    17
    Hi
    I cant find a solution because all tutorials on the net are load from www
    I just want to load some stuff from local storage from IOS device itself as bundle

    Have simple secne. camera and light. there is a cube prefab named Cube

    I want to just test things out simple. so i copy paste this from unity manual:

    UNITY MANUAL EXAMPLE:

    1. void Start()
    2. {
    3. var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle"));
    4. if (myLoadedAssetBundle == null)
    5. {
    6. Debug.Log("Failed to load AssetBundle!");
    7. return;
    8. }
    9. var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject");
    10. Instantiate(prefab);
    11. myLoadedAssetBundle.Unload(false);
    12. }
    MY TEST:

    1. void Start()
    2. {
    3. var myLoadedAssetBundle = AssetBundle.LoadFromFile("Users/MyUser/Documents/Game/AssetBundles/iOS/Cube".Combine(Application.streamingAssetsPath, "myassetBundle"));
    4. if (myLoadedAssetBundle == null)
    5. {
    6. Debug.Log("Failed to load AssetBundle!");
    7. return;
    8. }
    9. var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject");
    10. Instantiate(prefab);
    11. myLoadedAssetBundle.Unload(false);
    12. }
    I entered my path "Users/MyUser/Documents/Game/AssetBundles/iOS/Cube" where path is, but it is clearly wrong.

    Please explain to me what i am doing wrong so i can fix this. Thank you.
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    First of all, your path does not start with '/', if it's an absolute path, it should.
    Not sure if I read it correctly: you wan't to load asset bundle from your computer on iOS device? You can't do that.
     
  3. Amitr

    Amitr

    Joined:
    Mar 3, 2013
    Posts:
    17
    thank you. does asset bundle should only be used for adding content from a server?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,722
    No, you can put AssetBundle in any location that is accessible for your application.
     
  5. Amitr

    Amitr

    Joined:
    Mar 3, 2013
    Posts:
    17
    Thanks
    no computer : )

    i want to load from the device itself
     
  6. Amitr

    Amitr

    Joined:
    Mar 3, 2013
    Posts:
    17
    I just want to take some stuff that i know are global like UI and main things and place them in an asset bundle. So i can load them thru code without having them in the inspector first.