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?

Try port forwarding then, it could be an issue with your LAN, if you don't know how to just google something like "How to port forward my insert ISP here router" and find a guide. Then use your public address instead of your LAN address to connect to your host.

1 Answer

1

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.