Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 wijesijp · Sep 08, 2016 at 08:13 AM · assetbundlewwwloadfromcacheordownload

Save a prefab from asset bundle

I am writing a game that has downloadable content using asset bundle.

Once it is downloaded we can load it from cache using WWW.LoadFromCacheOrDownload

Is it the correct way to load it from the cache after downloading all the time?

Can the player clear the cache without removing the game? If the player can clear cache we have to save the content to the device. Is there a way to save the downloaded content to a location on the device?

Is it possible to save something like a prefab to the device ?

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 tqkiettk10 · Sep 08, 2016 at 10:27 AM

I think you can download assetbundle and save it into device Sample code: IEnumerator downloadAssetbundle(string url, string path) { WWW www = new WWW(url); //link of bundle file yield return www; System.IO.FileStream cache = new System.IO.FileStream(path, System.IO.FileMode.Create); cache.Write(www.bytes, 0, www.bytes.Length); cache.Flush(); cache.Dispose(); cache.Close(); }

And then you can load this assetbundle from device. This just my idea :) Sorry with my bad english

Comment
Add comment · Show 10 · 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 wijesijp · Sep 08, 2016 at 11:52 AM 0
Share

This is a great idea ...

I am using the example listed here; https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager

This will return "AssetBundleLoadAssetOperation" object. Don't have access to WWW object.

Is there a way to convert unity object into bytes and save it?

something like GameObject to bytes ...

avatar image Bonfire-Boy wijesijp · Sep 08, 2016 at 12:04 PM 1
Share

I've always done it the way @tqkiettk10 describes, using Application.persistentDataPath as the root of the path I'm saving the file to. Note that their code does nothing that's specifically related to asset bundles - it simply downloads a file and saves it locally. Then you can load the asset bundle using the same path.

You can also check to see if the file exists locally, before trying to download it.

avatar image tqkiettk10 wijesijp · Sep 08, 2016 at 12:46 PM 0
Share

@wijesijp me to. when you build assetbundle you get 2 file like asset and asset.manifest. Put it into your host and get link. Use my code to download and store it. example: you upload it in to http://unity3d.com/assetbundle/ folder

 class Download$$anonymous$$anager : $$anonymous$$onobehaviour 
 {
 string assetbundleUrl = "http://unity3d.com/assetbundle/";
 string assetName = "asset";
 string path = "/Assetbundles/";
 
 void Start()
 {
          path = Application.persistentDataPath + path + Utility.GetplatformName() +"/"; // Utility.GetplatformName() in assetbundles-and-assetbundle-manager tutorial. this just get Current platform name. you need using Assetbundles package
          StartCoroutine(downloadAssetbundle(assetbundleUrl , assetName, path)); 
 }
 IEnumerator downloadAssetbundle(string url, string assetName, string path) 
 { 
         // download asset file
          WWW www = new WWW(url + assetName);
          yield return www; 
          System.IO.FileStream cache = new System.IO.FileStream(path + assetName, System.IO.File$$anonymous$$ode.Create); 
          cache.Write(www.bytes, 0, www.bytes.Length); 
 
          //download mainfest file
          string mainfestName = assetName + ".mainfest";
          www = new WWW(url + mainfestName);
          yield return www; 
          cache = new System.IO.FileStream(path + mainfestName, System.IO.File$$anonymous$$ode.Create); 
          cache.Write(www.bytes, 0, www.bytes.Length); 
 
          cache.Flush(); 
          cache.Dispose(); 
          cache.Close(); 
 }
 }

hope this help!

avatar image wijesijp tqkiettk10 · Sep 08, 2016 at 02:29 PM 0
Share

This helps a lot.

https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager

This example resolve assets bundle dependencies. That is why I was thinking of using it.

I can see how the above code can save the data to local device.

Is it possible for you to list some code that I can use to resolve asset dependencies and get the actual object?

For example we have a prefab with a texture on it ....

Show more comments
Show more comments
avatar image wijesijp wijesijp · Sep 09, 2016 at 11:31 AM 0
Share

O$$anonymous$$ i understand what you are trying to do now!

We can use the AssetBundle$$anonymous$$anager to load an asset that is downloaded to the disk from your first code.

For this to work, we have to download all the dependencies from your first code right?

For example if I have a prefab in my asset bundle. Let's say it has a material and a texture. Downloading prefab and it's manifest is not enough right ?

We have to check the manifest of the prefab and download all the dependencies, the material and the texture.

We have to loop through the prefab's manifest and download the dependencies with your first code?

avatar image tqkiettk10 wijesijp · Sep 09, 2016 at 01:45 PM 0
Share
  1. No, if we have prefab and it contain material and texture apply on it, we just need set assetbundle name to the prefab (not set to material and texture) example we set bundle name of the prefab call "asset" https://unity3d.com/sites/default/files/assetbundlename.png , when we build assetbundle we will get 2 file "asset" (don't have extendsion) and "asset.manifest" all the dependencies will automatic add by unity to asset (we can will the file size to see). Upload it to server. Download and store it.

  2. we do't need say anything. Yes just download "asset" file my downloadAssetbundle function will download asset file and auto download asset.manifest file (just put them in same folder in your hosting). add should add some code to check if "assetfile" was downloaded befor call download (using System.IO you can search it) ... so a variables assetBundleName and assetName in LoadAssetDemoScript will like this

     public string  assetBundleName = "asset";
         public string assetName ="name of your prefab";
    
     
    
    
    
    

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

61 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WWW::Dispose doesn't work 1 Answer

Save Hash128 from Asset Bundle Manifest 2 Answers

AssetBundle, problem whit the version 0 Answers

LoadFromCacheOrDownload is sensibly slower than WWW, why? 1 Answer

How to download multiple asset bundles in serial order? The error of "cant load 'name' assetbundle as it is already loaded" comes after first assetbundle download. Please help. Needed urgently! 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