Version: 2022.3
言語: 日本語
アセットバンドルにパッチを適用する
Unity の Asset Bundle Browser ツール

トラブルシューティング

この項では、AssetBundle (アセットバンドル) を使用したプロジェクトでよくある問題をいくつか解説しています。

アセットの重複

Unity’s AssetBundle system will discover all dependencies of an Object when the Object is built into an AssetBundle. This is done using the Asset Database. This dependency information is used to determine the set of Objects that will be included in an AssetBundle.

Assignment to AssetBundles happens at the Asset level. The Objects inside an Asset that is explicitly assigned to an AssetBundle will only be built into that single AssetBundle. Depending which signature of BuildPipeline.BuildAssetBundles is called, an Asset is “explicitly assigned” either by setting the Asset’s AssetImporter.assetBundleName property to a non-empty string, or by listing it in AssetBundleBuild.assetNames.

Any Object that is part of an Asset that is not explicitly assigned in an AssetBundle will be included in each AssetBundle that contains any Objects that reference it.

In other words, if two different Objects are assigned to two different AssetBundles, but both have references to a common dependency Object, then that dependency Object will be copied into both AssetBundles. The duplicated dependency will also be instanced, meaning that the two copies of the dependency Object will be considered different Objects with a different identifiers. This will increase the total size of the application’s AssetBundles. This will also cause two different copies of the Object to be loaded into memory if the application loads both of its parents.

この問題の解決方法はいくつかあります。

  1. 異なるアセットバンドル内にビルドされた複数のオブジェクトが依存を共有しないようにする。依存を共有するオブジェクトは、その依存を重複させることなく同じアセットバンドル内に配置することができます。

    • この方法は通常、依存の共有が多いプロジェクトには適していません。再ビルドや再ダウンロードが過剰な頻度で必要なモノリシックなアセットバンドルが出来てしまい、効率性が損なわれる可能性があります。
  2. 同じ依存を共有する複数のアセットバンドルが同時に読み込まれないようにアセットバンドルを分類する。

    • This method may work for certain types of projects, such as level-based games. However there is still a trade-off, because duplicated objects will increase the build time and sizes of the project’s AssetBundles, and could impact loading times.
  3. 全ての依存アセットが、その所属するアセットバンドル内に確実にビルドされるようにする。これによりアセットの重複が起きる可能性は無くなりますが、複雑な状況が発生します。アプリケーションは、異なるアセットバンドル間における依存をトラッキングし、 AssetBundle.LoadAsset APIs の呼び出しが行われる前に正しいアセットバンドルが確実に読み込まれようにしなければなりません。

Object dependencies are tracked via the AssetDatabase API, located in the UnityEditor namespace. As the namespace implies, this API is only available in the Unity Editor and not at runtime. AssetDatabase.GetDependencies can be used to locate all of the immediate dependencies of a specific Object or Asset. Note that these dependencies may have their own dependencies so this can be a recursive calculation. The assignment of Assets to AssetBundles will either be defined explicitly by passing arrays of AssetBundleBuild structures when calling BuildPipeline.BuildAssetBundles, or can be queried using the AssetImporter API. It is possible to write an Editor script that ensures that all of an AssetBundle’s direct or indirect dependencies are assigned to AssetBundles, or that no two AssetBundles share dependencies that have not been assigned to an AssetBundle.

Note: When building AssetBundles with the Addressables package, the Addressables Analyze window can be used to discover duplicated assets.

スプライト アトラスの重複

The following sections describe a quirk of asset dependency calculation code when used in conjunction with automatically-generated sprite atlases.

自動生成されたスプライト アトラスは全て、その生成元のスプライト オブジェクトが含まれるアセットバンドルに割り当てられます。スプライト オブジェクトが複数のアセットバンドルに割り当てられている場合、そのスプライト アトラスは単一のアセットバンドルに割り当てられるのではなく、複製されます。スプライト オブジェクトがどのアセットバンドルにも割り当てられていない場合、そのスプライト アトラスも、どのアセットバンドルにも割り当てられません。

スプライト アトラスの重複を確実に防ぐためには、同じスプライト アトラス内にタグ付けされた全てのスプライトが、確実に同じアセットバンドルに割り当てられるようにしてください。

Android のテクスチャ

Android のエコシステムではデバイスが極度に断片化されるため、テクスチャをいくつかの異なる形式に圧縮する必要が頻繁に生じます。全ての Android デバイスは ETC1 に対応していますが、 ETC1 はアルファチャンネルを持ったテクスチャには対応していません。 OpenGL ES 2 に対応する必要のないアプリケーションの場合、問題を解決する最もシンプルな方法は、ETC2 を使用することです。 ETC2 には全ての Android OpenGL ES 3 が対応しています。

Most applications need to ship on older devices where ETC2 support is unavailable. One way to solve this problem is with AssetBundle Variants. (Please see Unity’s Android optimization guide for details on other options.)

AssetBundle Variant を使用するには、 ETC1 を使用してクリーンに圧縮できないテクスチャは全て、テクスチャ専用のアセットバンドル内に分離する必要があります。次に、 DXT5 や PVRTC、ATITC などの、vendor-specificのテクスチャ圧縮形式を使用して、Android エコシステムにおける ETC2 非対応のスライスに対応するために、これらのアセットバンドルのバリアントを十分量作成します。それぞれの AssetBundle Variant に関して、それに含まれるテクスチャの TextureImporter 設定を、そのバリアントに適した圧縮形式に変更してください。

ランタイムでは、各種テクスチャ圧縮形式への対応は SystemInfo.SupportsTextureFormat API で判定できます。この情報は、対応された形式で圧縮されたテクスチャを含む AssetBundle Variant の選択と読み込みに使用されます。

Android のテクスチャ圧縮形式についての更なる情報はこちらでご確認いただけます。

Interactions between Shaders and AssetBundles

When you build an AssetBundle, Unity uses information in that bundle to select which shader variants to compile. This includes information about the scenes, materials, Graphics Settings, and ShaderVariantCollections in the AssetBundle.

Separate build pipelines compile their own shaders independently of other pipelines. If both a Player build and an Addressables build reference a shader, Unity compiles two separate copies of the shader, one for each pipeline.

This process doesn’t account for any runtime information such as keywords, textures, or changes due to code execution. If you want to include specific shaders in your build, either include a ShaderVariantCollection with the desired shaders, or include the shader in your build manually by adding it to the Always Included Shaders list in your graphics settings.


アセットバンドルにパッチを適用する
Unity の Asset Bundle Browser ツール
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961