Nine, asset dependencies, how Addressables interact with other project assets

When you include a scene in your project build settings and build the player, Unity includes that scene and any assets used in the scene in your game or application's built-in data. Similarly, Unity includes any assets in the project's assets folder in a separate collection of built-in assets. (The difference is that assets in a scene are only loaded as part of a scene, whereas assets in assets can be loaded independently.)

Addressable assets can be built into your game or application as an additional set of "local" assets, or kept outside of your game build as "remote" assets that are hosted on a server and downloaded when needed. You can update remote assets independently of the application itself (although remote assets cannot contain code, so you can only change assets and serialized data).

How project assets are exported to player builds

However, if you use the same asset in multiple classes, Unity will duplicate the asset at build time instead of sharing a single instance. For example, if you use a material in a built-in scene, and you also use it in a prefab located in the assets folder, you'll end up with two copies of that material in your build - even if the material asset itself is not located in the resource. If you then mark the same material as addressable, you end up with three copies. (Files in the project's StreamingAssets folder can never be referenced by assets outside of that folder.)

notes

Before building the player, you must do content building on the addressable assets. During player build, Unity copies your local Addressables to the StreamingAssets folder so that they are included in the build along with any assets you place in StreamingAssets. (These assets are removed at the end of the build process.) It is your responsibility to upload the remote Addressables file generated by the content build to your hosting service. See builds for details.

When you use Addressables in your project, Unity recommends that you move the Scene and any data in the Assets folder into the Addressable group and manage them as Addressables.

The list of Build Settings scenes must contain at least one scene. You can create a minimal scene to initialize your application or game.

Small amounts of data in the Resources folder usually don't cause performance problems. If you use a 3rd party package that puts assets there, you don't need to move them unless they cause problems. (Addressable assets cannot be stored in the Resources folder.)

reference child object

Unity determines in part what to include in a content build based on how your assets and scripts reference each other. Subobject references further complicate the process.

If an AssetReferencepoints to a sub-object of an addressable asset, Unity will build the entire object to AssetBundlebuild time. Unity only builds the subobject as an implicit dependency if you point to an Addressable object that directly references the subobject AssetReference(eg GameObject, or ).ScriptableObjectSceneAssetBundle

Asset and AssetBundle dependencies

When you add an asset to the Addressables group, the asset is packaged into an AssetBundle when you build the content . In this case the asset is explicitly included in the bundle, in other words it is an explicit asset.

If an asset references another asset, the referenced asset is a dependency of the original asset. This is called asset dependency. If an asset is packaged into Assetbundle A and the referenced asset is packaged into AssetBundle B, then bundle B is a dependency of bundle A. This is called an AssetBundle dependency. See the AssetBundle dependencies man page for details.

The handling of asset dependencies depends on whether they are also addressable. Addressable dependencies are packaged into an AssetBundle according to the settings of the group they are in - this can be the same bundle as the referenced asset, or a different bundle. A non-addressable dependency is included in the bundle of the asset it references. The referenced asset is implicitly included in the bundle, in other words, it is an implicit asset.

hint

Use the Bundle Layout Preview  Analyze rules to view explicit and implicit assets that will be included in AssetBundles based on the contents of the Addressables group. This is useful when previewing assets before building content. Use the build layout reporting tool to display more details about the AssetBundles generated by content builds.

If multiple Addressables reference the same implicit asset, a copy of the implicit asset will be included in each package containing the referenced Addressable.

 

Non-addressable assets are copied into each package with reference addressable

A subtle consequence that can occur when an implicit asset is contained in multiple packages is that multiple instances of the asset can be instantiated at runtime instead of the single instance your game logic expects. If you change instance state at runtime, only objects from the same package will see the change, since all other assets will now have their own instance instead of sharing a common instance.

To eliminate this duplication, you can make the implicit asset addressable and include it in one of the existing bundles or add it to a different bundle. The bundle the asset was added to will be loaded whenever you load one of the Addressables that reference it. If the Addressables are packaged into a different AssetBundle than the referenced asset, then the bundle containing the referenced asset is an AssetBundle dependency.

Note that when you load any asset in the current bundle, the dependent bundle must be loaded, not just the asset containing the reference. While not loading any assets from other AssetBundles, loading a bundle has its own runtime cost. For more information, see Memory impact of loading AssetBundle dependencies.

hint

Use the Check Duplicate Bundle Dependencies  Analyze rule to identify and resolve unwanted duplication of assets caused by project content organization.

Guess you like

Origin blog.csdn.net/youmangu/article/details/129862574