Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Raigex · Jul 10, 2012 at 08:45 PM · androidassetassetbundlesstorage

How to load an AssetBundle from sdcard

I am trying to load an asset bundle from my external storage (sdcard). On regular android it is easy

Environment.getExternalDirector().getPath() + file.extendsion

I cant seem to find where the external directory is with unity. I have tired

file://sdcard/file.ext

file:///sdcard/file.ext

file:///mnt/sdcard/file.ext and everything in between.

I am trying to load my asset bundles with this code AssetBundle bundle = AssetBundle.CreateFromFile("file:///sdcard/animals.unity3d"); but it keeps saying

Failed to open file at path: file:///sdcard/animals.unity3d or whichever string i use for the file. I am getting really frustrated with this,and I cannot find any answers here that actually work.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Raigex · Jul 10, 2012 at 09:30 PM

I have found the answer. I was trying to open with Create from file but if you use www.LoadfromCachOrDownload("file://sdcard/filename.ext") it will load it up without any delay. Although I am not sure if it will work on all android devices so if anyone has a better way please post it.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image elixir-bash · Nov 08, 2012 at 12:26 PM 0
Share

hey raigex, this dint work for me. Im testing using HTC sensation can you tel me , how you got it work lil elaborately :)

avatar image Raigex · Nov 09, 2012 at 06:50 PM 0
Share

You should not use file://sdcard/filename.ext If you want to do this then here is how. Save the file you want to load in Application.persistantDataPath/your/sub/folders
then load it like this:
[code] WWW.LoadFromCacheOrDownload("file://" + Application.persistantDataPath + "/your/sub/folders/file.extension", 0) [/code]
This will load from a local copy of the file.

avatar image
0

Answer by sanketprabhu · Apr 22, 2016 at 10:25 AM

AssetBundle is platform specific . While exporting AssetBundle make sure that its exported for Android platform.

Then that Example.unity3d file on SDCard and just attach following C# code snip. to empty GameObject.

example URL of file on Android device SD-card

**string bundleURL = "file:///mnt/sdcard/AndroidCube.unity3d";**

C# Script:

 void Start() {  
         StartCoroutine(DownloadAndCache());
 
         }
 
     // Update is called once per frame
     IEnumerator DownloadAndCache() {
 
         while(!Caching.ready)
             yield return null;
         
         // example URL of file on PC filesystem (Windows)
         // string bundleURL = "file:///D:/Unity/AssetBundles/MyAssetBundle.unity3d";
         
         // example URL of file on Android device SD-card
         string bundleURL = "file:///mnt/sdcard/AndroidCube.unity3d";
         
         using (WWW www = WWW .LoadFromCacheOrDownload(bundleURL, Version)) {
             yield return www;
             
             if (www .error != null)
                 throw new UnityException("WWW Download had an error: " + www .error);
 
             // Load and retrieve the AssetBundle
             AssetBundle bundle = www .assetBundle;

Ten do whatever you want do with that assets. Imp: make sure in Manifest permission for ReadExternalSDcard is there

Enjoy....

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AssetBundleManager.LoadAssetAsync() doesn't work on some android devices (or is very slow) 2 Answers

On Android, how can I update files in the StreamingAssets folder? 1 Answer

Storing mobile data - limits on mobile 1 Answer

How to include assets in an android plugin (aar)? 3 Answers

How to Load Asset Bundle on Android ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges