- Home /
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?
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.
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.
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.
There is some cache management available using the Cache class. That will let you find out if an asset bundle version is already cached...
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.
Your answer
Follow this Question
Related Questions
Unity5 upgrade invalid serialized file version 0 Answers
How to set static size all game object? 0 Answers
Loading prefabs with script references from assetbundle 0 Answers
Loading GameObject with the Script Attached from the AssetBundle. 0 Answers
The AssetBundle can't be loaded because it was not built with the right version or build target. 0 Answers