- Home /
Storing a part of a complex asset in an asset bundle
I have a number of models in 3d Studio Max with multiple materials per model. Additionally those objects share a number of materials between them. For example Device1 have materials 1,2,3 and 4 applied; object Device2 have materials 1 and 5 applied; and Device3 has material 4 applied.
To avoid spawning different identical materials upon importing those models in unity I import them in a single FBX file. I then have and asset with a number of children. To be able to place them separately inside a scene I create a prefab for each object (child asset). I get something like this: http://img406.imageshack.us/i/fbximport.jpg/
Now I store all materials in an asset bundle, and want to store models in different asset bundles.
The question is: if I place a prefab Device1 in an asset bundle with BuildAssetBundleOptions.CompleteAssets option, will it place the whole asset in the bundle or only the mesh that prefab is linked to? Also what sequence of push/pop dependencies should I use to achieve the right result?
Answer by skovacs1 · Dec 09, 2010 at 06:31 PM
See the docs which say:
For example if you pass a Mesh into the BuildPipeline.BuildAssetBundle function and use CompleteAssets it would also include the game object and any animation clips in the same asset.
Essentially CompleteAssets will include everything that is setup on the asset.
The Push/Pop dependencies to achieve "the right result" depend on what you mean by "the right result". What is the result that you desire?
"See the docs which say:" That part of the doc is what I don't get. Device1 prefab reference Device_$$anonymous$$ asset (which is a child of another asset) and a mesh Device_$$anonymous$$. If I pass Device1 prefab to BuildAssetBundleFunction with CompleteAssets will it drag the whole Devices asset or Device_$$anonymous$$ asset only?
"What is the result that you desire?" I want only Device_$$anonymous$$ asset included in the bundle when I pass Device1 prefab to BuildAssetBundle function, not Box1 or OilTank01 nor any of the materials.
The problem is then not what CompleteAssets does, but the relationship between assets. If you've separated Device_$$anonymous$$ of the prefab Devices into another prefab (Device1), Device1 is now a separate asset from Devices. They may use the same shared$$anonymous$$esh or shared$$anonymous$$aterials which would be bundled with them, but bundling Device1 will not include the Devices prefab or its children as they are separate non-dependent assets. They depend on the same resources, but not on each other. Device1 has no direct connection to Devices or any of it's children.
You can change all sorts of things about Devices or Device$$anonymous$$ or Device1 and with the exception of changing any shared assets, changes to one will not affect the other. You can add a script to the Device$$anonymous$$ in Devices, but the script will not be added to Device1 because they are separate.
I am with you in noting where the docs are lacking and you are correct that this particular one is confusing. A $$anonymous$$esh doesn't have a GameObject to include, so the description doesn't really make sense. I believe that they were referring to a $$anonymous$$eshFilter Component or prefabs with FBXImporters or the like which would have $$anonymous$$esh and a specific GameObject to include.
Thank you for the answers. I think I don't fully understand the way dependencies between assets and game objects work in Unity.