1
\$\begingroup\$

From http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundle.html, I am using the sample code

using UnityEngine;
using UnityEditor;
public class ExportAssetBundles {
    [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
    static void ExportResource () {
        // Bring up save panel
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection.
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, 
                                           BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
            Selection.objects = selection;
        }
    }
    [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
    static void ExportResourceNoTrack () {
        // Bring up save panel
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection.
            BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
        }
    }
}

To build an AssetBundle. However, whenever I run this on a prefab, I noticed that Unity switches the platform to WebPlayer and THEN builds the bundle. But I need the AssetBundle to be built for iOS and Android - I don't need WebPlayer bundles.

Why does it keep switching to WebPlayer platform whenever I run this? How can I build for iOS and Android?

My prefab is just an object with a Sprite Renderer.

\$\endgroup\$
2
\$\begingroup\$

Notice in that documentation the optional last parameter: BuildTarget targetPlatform = BuildTarget.WebPlayer

In other words, if you don't explicitly set the target platform then it will default to target web player. To make it target the current platform, tell it: EditorUserBuildSettings.activeBuildTarget

Frankly, I would file this as a bug against that documentation. They should really make this fact more explicit, perhaps by adding it to their sample code or at least having a WARNING note that you should use .activeBuildTarget for mobile platforms.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .