problem creating assetBundle : size is way too small

I’ve implemented the script to export a prefab as an asset bundle as described here : Unity - Manual: Preparing your application for In-App Purchases (IAP)

However, the resulting filesize is like 4kb; but my prefab should be about 1mb minimum, so clearly the asset is exporting badly.

What could be wrong? Documentation for this feature (which is pro, no less) is really really lacking.

Update:

Turns out ScriptableObject used a lot of disk space, there is an other way out:

string path = UnityEditor.AssetDatabase.GetAssetPath(objectToBuild) ;
UnityEditor.AssetDatabase.CopyAsset(path, "Assets/"+objectToBuild.name+".bytes") ;

Duplicate the object and rename it with “.bytes” extension, pack those .bytes files into assetBundle, then delete 'em.

Note that files in assetBundle are accessing without the extension name, so create the bundle with .bytes copy will do no harm.


In this page unity documented as following: “If you want to include files with custom binary data, they should have the extension “.bytes”.”

I tied to export a txt file which changed extension to “sdta”. The size was 176 bytes.

Then export 10 sdta file, bundle size increased to 180 bytes.

It does exported, but not in the right way.

I think custom typed Object just exported reference data but not the file data.

So, all we need to do is export the file using ScriptableObject like this:

public class BytesHolder : ScriptableObject
{
	public byte[] dataBytes ;
	
	public static BytesHolder GetHolderObject(string path)
	{
		//	Check file exist 
		//	read file length and create bytesHolder object
		//	read data
		//	return
	}
}

When building the bundle, use BuildPipeline.BuildAssetBundleExplicitAssetNames and specify the name of that object.

Export ScriptableObject like this:

BytesHolder holder = BytesHolder.GetHolderObject("foo path");
AssetDatabase.CreateAsset(holder, "Assets/objects_names.asset");
//  Export
AssetDatabase.DeleteAsset("Assets/objects_names.asset") ;

Just figure this out, will give it some test and post further detail.