• 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 Alanimator · Dec 07, 2013 at 10:22 PM · c#assetbundleassetplatform

how to download Asset Bundles from website to Application.dataPath across platforms ?

I'm putting an exported bundle online , it can be download but I only know how windows functions , i know nothing of Linux nor Mac.

I would have to redirect the download path to the folder hosting the executable game file bit i do not know how to accomplish that .

how can i get this done ?

when i have the bundle in the file location i then set the path for which the bundle is fetched using

 Application.dataPath

then after writing the appropriate code , the bundles should be instantiated in my game on play.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tomer-Barkan · Dec 08, 2013 at 06:09 AM

The AssetBundle itself is just the assets loaded into memory, it cannot be saved to the disk. On the other hand, the WWW object, downloads the file itself, so before converting the WWW result into an AssetBundle, you can save it to the disk, using WWW.bytes to get the bytes, and File.WriteAllBytes() to save to disk.

See complete answer here:

http://answers.unity3d.com/questions/19522/how-to-download-an-asset-bundle-to-local-hard-driv.html

In your case, you'll want:

 File.WriteAllBytes(Application.dataPath + "/" + filename, bytes);


Comment
Add comment · Show 7 · 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 Alanimator · Dec 08, 2013 at 02:08 PM 0
Share

The game is not going to be what triggers a download . I dont want the download to take place via the game . the user will be the one who clicks a download button which will then trigger the download .

I take your response into consideration . should i just tell the uses "copy and paste your download to this folder..."

currently i access and instantiate bundles into my game if the name of the bundle to be instantiated exists in a particular folder .

I do that using Unities cache loading example

 using System;
 using UnityEngine;
 using System.Collections;
 
 public class CachingLoadExample : $$anonymous$$onoBehaviour {
     public string BundleURL;
     public string AssetName;
     public int version;
     void Start() {
         StartCoroutine (DownloadAndCache());
     }
     
     IEnumerator DownloadAndCache (){
         // Wait for the Caching system to be ready
         while (!Caching.ready)
             yield return null;
         
         // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
         using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
             yield return www;
             if (www.error != null)
                 throw new Exception("WWW download had an error:" + www.error);
             AssetBundle bundle = www.assetBundle;
             if (AssetName == ""){
                 GameObject ts = (GameObject)Instantiate(bundle.mainAsset);
                 
                 ts.name = (bundle.mainAsset.name.Replace("(Clone)",""));
 
             }
             else
                 Instantiate(bundle.Load(AssetName));
 
 
             // Unload the AssetBundles compressed contents to conserve memory
             bundle.Unload(false);
             
         } // memory is freed from the web stream (www.Dispose() gets called implicitly)
 
     
     }
 }

 
avatar image Tomer-Barkan · Dec 08, 2013 at 02:28 PM 0
Share

I don't get it... According to the code you posted, the download is being done by Unity. If you want the download done elsewhere, simply have the other tool, whatever it is, download the bundle and place it in the correct folder, then have unity load the bundle from the file system. What exactly are you unable to do?

avatar image Alanimator · Dec 08, 2013 at 02:42 PM 0
Share

there are two download stages , one where the uses goes online and downloads a file which is an asset bundle .

the bundle by default will not be downloaded into the game application folder so I need to get the bundle to the folder.

but i dont want users to see where the folder is located now how the asset is imported into the game.

once the bundle is in the game application folder . the code I posted will search that folder and instantiate the object.

I think I found a way to get the bundle downloaded from the internet to the games application folder . I will use a file browse dialogue within the game . so the user simply clicks on the downloaded bundle from there and it is copied into the game application folder .

avatar image Tomer-Barkan · Dec 08, 2013 at 02:57 PM 0
Share

Yes, that should work, as long as the game application has permission to access the file wherever it is located before copying it to the game application folder.

avatar image Tomer-Barkan · Dec 09, 2013 at 06:25 AM 1
Share

There's a usage example at the bottom of the link.

The idea is that you create an instance of the FileBrowser, and then every frame that you want it displayed you call it's OnGUI() method from within the $$anonymous$$onoBehaviour's OnGUI().

In the constructor of the FileBrowser you need to pass it a callback method (`FileSelectedCallback` in the example), that will be called automatically once a user selects a file.

So basically you can just use the example as is, but change the callback FileSelectedCallback to do whatever you want with the selected file, and change the OnGUI$$anonymous$$ain to display the layout that you want BEFORE the file browser is opened (ie everything that is outside the if.

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to create asset bundle in Project Tiny C# Mode? 0 Answers

Create 3d hexagonal terrain 1 Answer

Type"PathDefinition" does not contain a definition for "GetPathEnumerator" 0 Answers


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