I’m currently working on a project which requires a central level that acts as a portal to other levels. The most sane setup would be to build a central scene, and download another scene only when needed. So I started doing some research on how to load a downloaded scene and found out the unity site isn’t as clear as I would want it to be.
It’s still not 100% clear what can be packed into an Assetbundle (new scripts? complete scenes?).
So I made a summary on all options of downloading new assets or scenes…
Can anyone check the following summary? Are these assumptions right or did I misinterpret something?
ASSET BUNDLES
Asset bundles can contain a collection of assets. Assets are meshes, animations, textures, sound, or even complete prefabs (scripts are not considered to be an asset).
Look at Unity - Scripting API: BuildPipeline.BuildAssetBundle for a description of asset bundles.
They can’t be build within the standard unity menu’s. By using Editor scripts, the unity program can be extended to offer this functionality. The function for building such asset bundles can be found at Unity - Scripting API: BuildPipeline.BuildAssetBundle.
The assetbundle can be downloaded (with the WWW class) and instantiated with following code: Unity - Scripting API: WWW.assetBundle.
! BuildPipeline.BuildAssetBundle is a pro-only feature !
Functional in targets: web, standalone, others
STREAMED SCENES
An asset bundles can’t contain new scenes (or levels). Additional scenes however can be build with an Editor script.
How to build a scene can be found at Unity - Scripting API: BuildPipeline.BuildPlayer. The BuildPlayer function can build a scene into a playable unity3d file. With the BuildOptions set to BuildAdditionalStreamedScenes (Unity - Scripting API: BuildOptions.BuildAdditionalStreamedScenes) this unity3d file can be downloaded as an assetbundle from which the new scene can be loaded.
For loading a scene from an asset bundle, thus asset bundle doesn’t have to be initiated. After downloading the unity3d file, set it to a AssetBundle variable, and just load the scene with Application.LoadLevel or LoadLevelAdditive.
! BuildPipeline.BuildPlayer is a pro-only feature !
Functional in targets: web, standalone, others
STREAMED WEBPLAYER FILES
When a scene is built to a web player version, the resulting unity3d file can also be downloaded through the WWW class. Just call the LoadUnityWeb function of WWW after downloading the file.
This option fully replaces the current webplayer instance (like going to another url with the new unity3d file), so assets, variables, states etc won’t be transferred to the new webplayer instance.
This is the only solution for loading new scenes in the free version of unity.
Functional in targets: web