- Home /
How to - Dynamic content and asset bundles
Hi,
I'm relatively new to new to Unity development. I have content I will need loaded after the game has been deployed and I'm slightly confused on how to use asset bundles.
I have created a sample asset bundle using this tutorial:
http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundle.html
I have code on how to use asset bundles using this tutorial:
http://docs.unity3d.com/Manual/DownloadingAssetBundles.html
What these tutorials don't tell me is the following:
a) Are the assets literally just held on an FTP server somewhere or do you need to setup an "asset server"? I do have one setup and it looks to be more about version control.
b) how to a take an asset bundle and upload it to the server? If the server is nothing more than an FTP server, then I would be happy enough to write c# code to export to the location. I have an asset bundle I've built sitting on my c: drive, how do I make it available for download?
c) the tutorial for loading an asset references this line of code:
using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
What is the bundle url? One code sample gives this url as an example:
var www = WWW.LoadFromCacheOrDownload ("http://myserver.com/myassetBundle.unity3d", 5);
Again - I need to understand, is the myserver.com an asset server or just a file server somewhere, like IIS hosting a file? I've tried this via IIS and I get a 404 error.
d) Can anyone give me an example of loading an asset bundle from the local disk?
Thanks in advance!! Rob
Answer by LessThanEpic · Jan 28, 2015 at 01:13 AM
a) You can put the asset bundles wherever you want, either locally or on a server.
b) If you're putting the asset bundle on the server it doesn't really matter how you get it there. You can just use a regular ftp client if that's what you're used to.
c) The bundle url is just the path to where ever you put the bundle. The code example you reference is given the hypothetical situation that you have a website/server that you can hit by going to myserver.com and that you stored the asset bundle in the root folder of that server.
d) If you have an asset bundle on your local machine that you want to use you can just pass the file path (using forward slashes instead of backslashes). For example:
var www = WWW.LoadFromCacheOrDownload ("C:/Users/Sean/Desktop/assetbundle.unity3d", 5);
Thanks for your help! Ok so it seems the following:
a) These are just held on disk locally or on a server somewhere. Nothing special needs setup (like an "Asset Server"). Files should just be accessible through an address (local or web).
b) No problem, easy enough to understand. If on local disk, drop the file where I need OR if I just need to FTP the file to a server, no issues.
c) This is still slightly confusing. As a test I created an asset bundle, spun up local IIS on my Windows machine, created a web application in IIS and dropped the file into the web app directory to test (lets say http://localhost/mytestapp/samplebundle.unity3d).
When I try the code to pull it down using WWW.Load... it gives me 404 file not found (I get the same in a browser when I navigate to it but I didn't expect that to work). It's kinda like IIS doesn't know how to respond to the request. I tried the same thing on a web server I have public web facing (for arguments sake we'll say https://www.myserver.com/mywebapp/samplebundle.unity3d). This also responded with a 404 error (file not found).
Not sure how to make this work. Do I need to enable some extensions on IIS to get the correct response? Or am I over thinking this?
d) Ok - local machine seems fine. Thanks for that! I got it going with this code for anyone else who needs it:
string path = EditorUtility.OpenFilePanel("Load Bundle", "", "unity3d");
AssetBundle assets = AssetBundle.CreateFromFile(path);
assets.LoadAll();
var loadedObject = (GameObject)assets.mainAsset;
Using IIS locally is a whole different can of worms. If you're trying to load a local asset bundle I wouldn'I wouldn't mess with a server. Just use the actual file path (C:/whatever). If that works then your Unity scripts are working. The fact that you can't hit iis through unity or the browser is a server issue and not related to your game code.
Also if you this works you should mark the answer as accepted.