I’ve been looking around, but I can’t find the official way of building AssetBundles from script in Unity 5+. The new AssetBundle system in Unity 5 allows for easier manual AssetBundle creation. This is great of course, but we have cases where we need to export thousands of them, so automation from script is the only reasonable way to go.
I’m currently using the classic BuildPipeline.BuildAssetBundle, but this method is deprecated, which is bugging me. Is there any new way I’m unaware of that allows you to add automation to the new manual AssetBundle creation? Or is the choice to either name thousands of objects by hand or to look at constant deprecation warnings?
Ah, little typo there. I could use that one, but how do I then mark which asset bundles to build from a script? (Because doing it manually is not option.)
That indeed sounds good. At first I thought you could only use this to define a subset of the Asset Bundles specified in the editor, but that does not seem to be the case according to the Scripting API:
“The array of AssetBundleBuild elements that is passed to the function is known as the “building map” and serves as an alternative to specifying the contents of bundles from the editor.”
So, this looks very hopeful.
Edit: That sort of works, but the dependencies are not collected. According to the manifest:
Assets:
Lets test again. Nope:
“Script asset “…cs” cannot be included into AssetBundle “…”.”
Including the serialized data was not an issue before, but I guess it’s trying to include the actual script file.
Edit3: So, added some file filtering to exclude files that end with .cs or .shader. (Very pretty.) Now the next one is:
Asset “Assets/Imported/Textures/diffuse_224.png” has been marked into more than one AssetBundles.
Which is true and I’m not going to make 400 copies of the same texture. So, next step is to use the Bundles() version as the Bundle() version and export them one by one.
Edit4: That makes things a lot (10x) slower and the dependencies are now listed as separate entries in the AssetBundle instead of dependencies.
Conclusion, I’ll stick with the deprecated version and keep the warning suppression.