Asset duplication happens when Unity recursively follows direct references to make sure that all required objects are included in the build. Assets and scenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary aren’t shared between different builds, so the same content might be duplicated both in the Player build and a content-only build that you make using AssetBundles or Addressables. For small objects this might not be a problem, but for large assets such as textures or meshes this can lead to large build sizes.
To avoid or minimize asset duplication, you can minimize the amount of content that goes into the Player build and put all the content into AssetBundles or Addressables instead.
To create a minimal Player build, include only a single starting scene containing a MonoBehavior that bootstraps the rest of the content loading using the AssetBundle or Addressable APIs. You should also avoid putting any assets into Resources folders that are also referenced by a content-only build. You can ship the output of the AssetBundle or Addressable builds with the Player build, using the StreamingAssets folder, or hosted on a CDN.
Unity uses the Asset Database to discover all dependencies of an object when it’s built into an AssetBundle. Unity uses this dependency information to determine the set of objects to include in an AssetBundle.
AssetBundle assignment happens at the asset level. Objects in an asset explicitly assigned to an AssetBundle are included only in that specific AssetBundle. Depending on the BuildPipeline.BuildAssetBundles method used, an asset is explicitly assigned either by setting its AssetImporter.assetBundleName property to a non-empty string, or by listing it in AssetBundleBuild.assetNames.
Assets can be duplicated in AssetBundles if the same asset is referenced from different AssetBundles. If that asset isn’t explicitly assigned to an AssetBundle then Unity copies its content inside each AssetBundle that references it.
For example, if two objects are assigned to separate AssetBundles but share a reference to the same dependency object, Unity duplicates the dependency object into both AssetBundles. These duplicated dependencies are also instanced, meaning the two copies are treated as distinct objects with unique identifiers. This increases the overall size of the application’s AssetBundles and results in two separate copies of the object being loaded into memory if both parent AssetBundles are loaded.
To prevent this from happening, make sure that shared assets are explicitly assigned to an AssetBundle. For more information, refer to Handling dependencies between AssetBundles. The Build Report Inspector is also a useful tool to identify duplication in AssetBundles.
Addressables has the same issue with duplication of implicitly referenced assets. In that case, you can avoid it by assigning shared assets to a group. The Addressables Analyze tool helps diagnose and resolve asset duplication.