How to create Asset Bundles in Unity by script



I think the only way to make an Asset Bundle in Unity is by using script, this one is taken from Unity official tutorial.

Have a folder named Editor in your Assets folder, and make this script inside it:

using UnityEngine;
using UnityEditor;
using System.IO;

public class CreateAssetBundles
{
	[MenuItem("Assets/Build AssetBundles")]
	static void BuildAllAssetBundles()
	{
  	string assetBundleDirectory = "Assets/StreamingAssets";
  	if (!Directory.Exists(Application.streamingAssetsPath))
  	{
    	Directory.CreateDirectory(assetBundleDirectory);
  	}
  	BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
	}
}

Name the file CreateAssetBundles.cs

And then, I think I better show it to you in this video…

loading...

4 thoughts on “How to create Asset Bundles in Unity by script

  1. Don’t use play mode. You just have to choose it from asset menu. And the script should be in editor folder

Leave a Reply to Habibie Cancel reply

Your email address will not be published. Required fields are marked *