Manual     Reference     Scripting   
  
Unity Manual > Advanced > Loading Resources at Runtime   

Loading Resources at Runtime

There are a number of scenarios where you want to include some kind of asset in your finished game that is not included inside the primary game executable; standalone or web player. One scenario is to slim a webplayer download size, and dynamically download and instantiate individual objects or items. This way only the relevant and needed objects are used by the end-user. Another scenario might be for downloadable content like additional weapons, environments, characters, or even full levels.

In Unity Pro, you can choose between two options for accomplishing these tasks: Asset Bundles, and Resource Folders. Unity Indie license holders can use Resource Folders only.

Asset Bundles (Unity Pro-only)

An Asset Bundle is an external collection of assets. You can have many Asset Bundles and therefore many different external collections of assets. These files exist outside of the built Unity player, usually sitting on a web server for end-users to access dynamically.

To build an Asset Bundle, you call BuildPipeline.BuildAssetBundle() from inside a script. In the arguments, you specify an array of Objects to be included in the built file, along with some other options. This will build a file that you can later load dynamically in the runtime by using AssetBundle.Load().

Resource Folders (Indie and Pro)

Resource Folders are collections of assets that are included in the built Unity player, but are not necessarily linked to any GameObject in the Inspector.

To put anything into a Resource Folder, you simply create a new folder inside the Project View, and name the folder "Resources". You can have multiple Resource Folders organized differently in your Project. Whenever you want to load an asset from one of these folders, you call Resources.Load().

If your target deployable is a Streaming Web Player, you can define which scene will include everything in your Resource Folders. You do this in the Player Settings, accessible via Edit->Project Settings->Player. Set the First Streamed Level With Resources parameter, and all assets in your Resource Folders will be loaded when this level streams in to the end-user.