• 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
Question by davidb1 · Sep 29, 2015 at 12:03 PM · unity 5assetbundle

Asset Bundle load locally

Hi, does anyone happen to know: I want to ship the game with the first version of my asset bundle already inside to prevent the first time download. Is there any way to do this?

Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image
Best Answer

Answer by Dave-Carlile · Sep 29, 2015 at 12:04 PM

The WWW class can load files locally by specifying a local path as the url. You can get the local file into the cache by specifying a local path on the first run of the game, then using the server path after that.

 if (only on the very first run of game)
 {
   // load the asset bundle from your local file into the cache
   WWW.LoadFromCacheOrDownload("file://local path and bundle_filename"...);
 }
 else
 {
   // from then on use the server version of the filename
   WWW.LoadFromCacheOrDownload("http://server path and bundle_filename"...);
 }


At first I was thinking this wouldn't work because it's going to think they're two different files. But from the LoadFromCacheOrDownload documentation:

Cached AssetBundles are uniquely identified solely by the filename and version number; all domain and path information in url is ignored by Caching. Since cached AssetBundles are identified by filename instead of the full URL, you can change the directory from where the asset bundle is downloaded at any time.

So as long as the name of the asset bundle matches in the local and server version you should be fine. Of course you still need some way to know there's a new version on the server so you can pass that new version number, otherwise it will continue to load the same version you have cached.

And this isn't anything I've done or tested but it seems viable.

Comment
jpatinop80

People who like this

1 Show 4 · 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 davidb1 · Sep 29, 2015 at 12:09 PM 0
Share

Would that enable me to load an asset bundle locally and if it has an update download it from the server? The main point is that I want unity to overwrite the pre-existing asset bundle as if it was downloaded from the server.

avatar image Dave-Carlile davidb1 · Sep 29, 2015 at 12:23 PM 0
Share

It sounds like you want WWW.LoadFromCacheOrDownload?

Edit: Er, no you don't... maybe there's some way to seed the cache with the initial version? I'm not sure.

But if you want to roll your own, you'd need to have some server API that let you check the latest version. Once there's a later version you'd start using LoadFromCacheOrDownload from then on.

avatar image Dave-Carlile davidb1 · Sep 29, 2015 at 12:34 PM 0
Share

There is some cache management available using the Cache class. That will let you find out if an asset bundle version is already cached...

avatar image Dave-Carlile davidb1 · Sep 29, 2015 at 12:45 PM 0
Share

Updated my answer with a possible solution. I've not worked with asset bundles much so there may be a better way to do it. But some flavor of this should work.

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there a way to make DLC in unity without assetbundle? 0 Answers

why the value of "bundle" variable is null? can anyone help please? 0 Answers

Unity3d: dynamically adding new asset bundles without re-building the project into an apk 0 Answers

Unity5 upgrade invalid serialized file version 0 Answers

How to set static size all game object? 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