에셋 번들 은 플랫폼별 비코드 에셋(예: 모델, 텍스처, 프리팹, 오디오 클립, 씬 전체)이 들어 있는 아카이브 파일이며 런타임 시점에 로드할 수 있습니다. 에셋 번들에는 서로 종속성을 표시할 수 있습니다. 예를 들어 한 에셋 번들의 머티리얼이 다른 에셋 번들의 텍스처를 참조할 수 있습니다. 효율적인 네트워크 전송을 위해 에셋 번들은 사용 요구 사항(LZMA 및 LZ4)에 따라 빌트인 알고리즘을 사용하여 압축할 수 있습니다.
에셋 번들은 다운로드 가능 콘텐츠(DLC)에 유용합니다. 초기 설치 크기를 줄이고, 최종 사용자 플랫폼용으로 에셋 로딩이 최적화되고, 런타임 메모리의 압박이 줄어듭니다.
An AssetBundle built for any of the standalone platforms can only be loaded on that platform. For example, a bundle built on iOS is not compatible with Android. One reason for this is that Shaders, Textures and other types of data are built into platform-specific formats based on the BuildTarget.
When you build or rebuild AssetBundles, you typically build all of the project’s AssetBundles together using a single API call. It is usually best not to build or rebuild them individually, because when built together, the Unity Editor makes decisions about how to reference or embed content in each AssetBundle which can depend on what is included in other AssetBundles. The exception to this is if you’re an advanced user who understands the references and dependencies among the AssetBundles in your project, in which case you can sometimes build just a subset of your project’s AssetBundles.
Because the APIs that you use to load AssetBundles are designed to be simple, they abstract away the details of how data is represented inside AssetBundles. However it can be useful to understand the structure, especially if you use tools to extract or examine the contents of an AssetBundle.
The AssetBundle is a container file format, similar to a zip file. It has a binary-format header and embeds additional files inside it. These additional files consist of two types:
The AssetBundle file always includes a serialized AssetBundle object. This object acts like a directory for the contents of the AssetBundle. This is the object you interact with via code to load Assets from a specific AssetBundle archive, and it is also used internally when loading Assets from AssetBundles with the Addressables API.
When an AssetBundle is built, the objects that are included are serialized using the definition from the version of the Unity Editor you used to build it, as well as the C# types defined in the Project that is built. The information for each type is recorded inside the AssetBundle in a structure called the Type Tree. This type information contributes somewhat to the size of the AssetBundle, but it is critical to enabling loading those objects when the version of the player does not match the Editor version at the time of the build. For many Unity features the types are quite stable and only change in minor ways between versions so the backward compatibility support works well. However in cases where Unity features change substantially it may not be possible to load the old data in a way that achieves the expected results in the newer version. In that case, you must rebuild the AssetBundle using the new version of Unity.
Unity does not support forward-compatibility, so loading an AssetBundle built with a new version of Unity into a Player that was built with an older version of Unity is likely to have trouble loading the content.
Note: By default the version of the Unity Editor that was used to build the file is included inside the AssetBundle header. This information can be useful when investigating backward compatibility issues. However, it can also result in AssetBundles being rebuilt unnecessarily, and cause unnecessary client downloads if a project is rebuilt after doing a minor upgrade of the Editor. To avoid this, you can exclude the Editor version, see BuildAssetBundleOptions.AssetBundleStripUnityVersion.
AssetBundles do not contain assemblies and are not used to distribute new C# classes or changes to existing classes. Rather, it is the Player Build that contains the compiled assemblies. This means to release code changes, you must rebuild and redistribute the main build of your game or app.
However, you can use AssetBundles to distribute new objects that are instances of the classes compiled into your Player build, such as new items for a game.
For example, AssetBundles can include ScriptableObject Assets. When you load that Asset from the AssetBundle Unity finds the matching class definition, based on the assembly name, namespace and class name. It creates an object that is an instance of that class and sets the fields of the object using the serialized values.
If the object was serialized based on an older definition of the class then Unity will use its backward compatibility support to match up whatever fields it can, based on the field names and other info recorded in the Type Tree.
Scripts often use Conditional Compilation to specify platform-specific code. For example, using scripting symbols like UNITY_STANDALONE, UNITY_IOS and UNITY_ANDROID. If fields on a class or struct are not compiled on some targets then the serialization of objects inside the AssetBundle will not include those fields (and they will not be included in the Type Tree). This is another reason that AssetBundles must be rebuilt for each platform that you target.
There are two supported APIs to build AssetBundles for Unity:
BuildPipeline.BuildAssetBundles
, AssetBundle
and UnityWebRequestAssetBundle
. This is the functionality described in this section of the Manual. However this method is quite low-level, for example it requires that you understand Asset dependencies, determine bundle assignments yourself and write your own build script.