Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity5 AssetBundle functions obsolete?

Tags:

unity3d

So I have read through the Unity5 AssetBundle changes, and understand them all perfectly. My problem is that a lot of functionality has been made 'obsolete', but the functions seem to still work and the Unity5 documentation is actually using obsolete functions.

My main concern is, how would I now, in Unity5, take a directory of prefabs and turn all of them into their own separate AssetBundles seperately? Not just one AssetBundle containing everything, but rather each built into it's own separate AssetBundle?

Ideally I would use the BuildPipeline.BuildAssetBundle function. But unity5 says that is obsolete. But if you look here: http://docs.unity3d.com/500/Documentation/Manual/managingassetdependencies.html

They are using that function in the manual.

Also it says the CollectDependencies option is obsolete and no longer needed. But I removed it from my code and then Unity spit out the error:

 Please specify BuildAssetBundleOptions.CollectDependencies or collect GameObject's components and pass as 'assets' parameter.
like image 853
rygo6 Avatar asked Mar 08 '15 04:03

rygo6


1 Answers

The new BuildPipeline.BuildAssetBundlestakes a AssetBundleBuild array as input. You can create a AssetBundleBuild[] and fill it with all the prefabs you want, as separate bundles:

//Create an array for 2 different prefabs.
AssetBundleBuild[] buildMap = new AssetBundleBuild[2];

//Make a buildMap for the first prefab.
AssetBundleBuild buildInfo1 = new AssetBundleBuild();
//The name of the bundle that the prefab will be saved as.
buildInfo1.assetBundleName = bundle1Name+".unity3d";

//Only one file for this prefab.
string[] prefabs1 = new string[1];
//The full path to the prefab.
prefabs[0] = prefab1Path;
buildInfo1.assetNames = prefabs1;

buildMap[0] = buildInfo1;


AssetBundleBuild buildInfo2 = new AssetBundleBuild();
//The name of the bundle that the prefab will be saved as.
buildInfo2.assetBundleName = bundle2Name+".unity3d";

//Only one file for this prefab.
string[] prefabs2 = new string[1];
//The full path to the prefab.
prefabs[0] = prefab2Path;
buildInfo2.assetNames = prefabs2;

buildMap[0] = buildInfo2

//Save the prefabs as bundles to the "bundleFolder" path.
BuildPipeline.BuildAssetBundles(bundleFolder, buildMap)
like image 64
Rasmus Øvlesen Avatar answered Oct 03 '22 04:10

Rasmus Øvlesen