- Home /
Why don't my Asset Bundles bundle?
HI all, I am trying to create an asset bundle in code by simply selecting a gameobject from the scene and hitting a button. My code creates a prefab version of the gameObject, attaches a couple of scripts and then bundles it up, ready for upload. However, I'm getting an error...
I am first creating a prefab like so:
prefab = EditorUtility.CreateEmptyPrefab("Assets/Prefabs/"+t.gameObject.name+".prefab");
EditorUtility.ReplacePrefab(t.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
...then I try to bundle it up using:
Selection.activeObject=prefab;
var selection = Selection.GetFiltered(typeof(GameObject), SelectionMode.DeepAssets);
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, bundlesPath, BuildAssetBundleOptions.CollectDependencies|BuildAssetBundleOptions.CompleteAssets );
This all works fine and a bundle is created in the right place but I get the error:Asset bundles can not include Editor Objects(Prefab).(?!) My asset bundles are just a gameobject with a couple of components attached (mesh renderer and a couple of my own scripts).
Any ideas?
I dont think Selection.activeObject=prefab; is actually selecting the created prefab. Could that be right?
@grimmy Have you found the solution? I have same problem.
Answer by grimmy · Feb 06, 2013 at 04:06 PM
Instead of
Selection.activeObject=prefab;
do
Selection.activeObject=AssetDatabase.LoadMainAssetAtPath("Assets/Prefabs/"+name+".prefab");
Your answer