- Home /
Exception when building asset bundle with variant using build map
Hi, I'm trying to generate AssetBundles using a build map (array of AssetBundleBuild
objects) sent to BuildPipeline.BuildAssetBundles
, as is shown in the second example in the documentation.
The issue appears when I try to create an asset bundle with a variant, which isn't shown in the documentation (or anywhere online). Assigning non-null-or-empty string to AssetBundleBuild.assetBundleVariant
, I get a slew of identical errors in the inspector stating the "Variant folder path cannot be empty."
The code I am using is:
var builds = new AssetBundleBuild[2];
builds[0] = new AssetBundleBuild
{
assetBundleName = mainBundleName,
assetBundleVariant = "variant1",
assetNames = new[] { "Assets/troops/troop/variant1/troop.prefab" }
};
builds[1] = new AssetBundleBuild
{
assetBundleName = mainBundleName,
assetBundleVariant = "variant2",
assetNames = new[] { "Assets/troops/troop/variant2/troop.prefab" }
};
BuildPipeline.BuildAssetBundles(ASSET_BUNDLE_OUTPUT_PATH, builds, BuildAssetBundleOptions.None,
EditorUserBuildSettings.activeBuildTarget);
Based on the workaround in this similar issue, I have tried putting the asset I am trying to turn into a bundle into various folder structures with the name of the bundle/variant/etc. all to no avail.
It is worth noting that when assigning the same bundle name and variant to this asset in the inspector and running BuildAssetBundles without a build map it runs fine, but I am trying to create an automated process...
Any help would be greatly appreciated. Thanks!
We are seeing the same slew of errors in the same use context with BuildPipeline.BuildAssetBundles with Unity 2017.1.0p4. It doesn't cause any noticable runtime issues but it does generate very large build logs and is probably slowing down the build.
I am having this problem as well, in the newest version of Unity 2017.1.1. There are no empty strings in the file paths or build paths. This has been happening since I started using Unity in 5.5.
EDIT: Upon learning a bit more about the AssetBundle system, I've learned this merely changes the output file name. The file name is what I was trying to control with the variant (which was horrible idea).
I got back to working on my AssetBundle framework, and the thought occurred to me to simply not set assetBundleVariant, and just append it to the assetBundleName.
So ins$$anonymous$$d of
AssetBundleBuild bundleBuild = new AssetBundleBuild
{
assetBundleName = "name";
assetBundleVariant = "variant";
}
You would have
AssetBundleBuild bundleBuild = new AssetBundleBuild
{
assetBundleName = "name.variant";
}
It's a hack, but it seems to be working for me so far.