How to store a prefab in an AssetBundle dynamically by an Editor Script?
Assume the prefab creation works fine:
var prefab = PrefabUtility.CreatePrefab("Assets/Prefabs/myPrefab.prefab", myGameObject, ReplacePrefabOptions.Default);
Means "prefab" is not null.
But now I want to store/save the prefab in an AssetBundle. How is this archived? My try:
var buildMap = new List<AssetBundleBuild> {
new AssetBundleBuild {
assetBundleName = "MyPrefab in an AssetBundle",
assetNames = new [] { AssetDatabase.GetAssetPath(prefab) }
}
};
var manifest = BuildPipeline.BuildAssetBundles("Assets/AssetBundle/uweTest.unity3d",
buildMap.ToArray(),
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows);
Any help would be great! Thanks in advance!
Answer by UweR7 · Aug 20, 2017 at 08:21 AM
The code abaove works fine. It does NOT contain any error. But: The prefab was NOT build/created because the project contained "other errors" that prevent "the system" to reach the "player" mode. After fixed these errors, the code worked as expected (and returned a non null value as manifest)
Strange unity editor behavior, because why was all other code running perfectly but not building the AssetBundle.
Hope this helps someone else.
Also strange: No one gave me a hint. Conclusion: $$anonymous$$y question was too stupid or the unity and/or the community is death!?
Your answer
Follow this Question
Related Questions
Editor script: Variable created on gameObject in editor set to missing on runtime 0 Answers
How can I get a reference to a Prefab in the Asset folder without instantiating it? 2 Answers
Editorscript: How to reference prefabs in editor not in awake or start 0 Answers
PrefabUtility.CreatePrefab() results in "not a valid asset file name" error? 2 Answers