Prefab Variants - Pulling Base Assets Into Bundle

How should I go about laying out my addressables which are prefab variants? We have a base prefab which contains core UI for a popup, and then we have multiple variants which are used in different scenes. When checking the analysis tool I can see that in each scene which uses a prefab variant, all of the base prefabs sprites are duplicated and pulled in. Is there a way I can get the base prefab and its assets into its own group so that all other bundles do not pull in and duplicate the base prefabs assets?

Adam

Any help here?

Have you tried making the base prefab into an addressable? I think this way each variant will point to this single reference and all the dependencies of the base will packed with that.

I did try this yes, didn’t work, still all assets were packed into the other groups.

You need to have direct references to the dependencies of a given prefab in a group, any group (in your case, the base prefab group). You can use the analyze tool to check implicit dependencies. They will directly relate to the assets that are not explicitly declared in any Addressables group and thus “unknown” to any dependency de-duplication.

So for your Base UI prefab, it will probably have textures or sprites, maybe animations, implicitly known to it. If you don’t want your variants implicitly making a copy for their bundles then you need to put those textures, sprites, animations into the Base group (or any other group - getting them explicitly exposed is the key thing). The implicit duplication thing is related to allowing developers to make bundles without having to load other bundles first - but if you explicitly declare the assets to the asset bundling system at the same build time, then you’re letting it know you’re going to handle loading the dependencies at runtime. With addressables you don’t handle it, that’s one of the things it’s doing for you at runtime - so usually it makes sense to be explicit about your implicit assets unless it’s clearly only ever associated with that prefab - or if you want the duplication (for more esoteric reasons).

Extra info. I believe prefab variants are only an editor concept. At build or runtime time a variant is baked out - such that the base prefab info is ignored. Still the textures and large assets are not baked out, more just the gameobject hierarchy + values on the components. So explicitly declaring your implicit assets is going to help remove your asset duplication.

A problem is if you want to know what your implicit asset dependencies are in code. It’s doable, the analyze tool shows you just enough to see how you might recover this information from the scriptable build pipeline (the ContentBuildInterface at the core of it), but there might be easier ways. It would be nice to have simple 1 line functions to call to get asset or scene dependency guids so you could write tools to configure your groups and make implicit dependencies explicit quickly.

TLDR: Run the analyze tool, find the implicit dependencies in your Base Prefab, and drag them from your project folder into the Base Prefab group. They will then only show up in one place for all bundles/groups.

1 Like