- Home /
AssetBundle.CreateFromMemory fails in WebPlayer
Hello everyone. I need to encrypt my assetBundles and download them into WebPlayer. I use default code from example:
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d"; IEnumerator Start () { // Start a download of the encrypted assetbundle WWW www = new WWW (url);
// Wait for download to complete
yield return www;
// Get the byte data
byte[] encryptedData = www.bytes;
// Decrypt the AssetBundle data
byte[] decryptedData = YourDecryptionMethod(encryptedData);
// Create an AssetBundle from the bytes array
AssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);
// You can now use your AssetBundle. The AssetBundle is not cached.
}
This is how I save the bundle:
BuildPipeline.BuildAssetBundle(objects[0], objects, bundlePath,
BuildAssetBundleOptions.CollectDependencies,
BuildTarget.WebPlayer);
I don't use Push/Pop Dependencies. Even when I don't use BuildAssetBundleOptions.CollectDependencies (when bundle contains of only one texture asset) - it still doesn't creates from memory in webplayer.
Webplayer log says:
Asset bundle is incomplete
I try this from webplayer in browser (Chrome/Firefox). My Unity version is 4.2.1f4 pro trial
Not sure if it's any help, but I did find this old forum thread mentioning a similar issue.
I have the same issue, and this thread doesn't help at all. It is just describing the problem, but not solving it
Answer by vasup · Oct 29, 2013 at 03:40 PM
I have found that the problem is not in CreateFromMemory method
CreateFromMemory fails because www.bytes array is empty
byte[] encryptedData = www.bytes; // www.bytes.Length is 0 here!
Btw I tried the code above on non encrypted bundle (the decryption method changed nothing in bytes).
At the same time www.assetBundle is accessible, this happens in WebPlayer, not in Editor.
So a different way to load raw bytes of assetBundle is needed. This can be done through Systen.Net.Socket as in unityweb: https://code.google.com/p/unityweb/ (also commercial package based on unityweb exists).
Your answer
![](https://koobas.hobune.stream/wayback/20220613120615im_/https://answers.unity.com/themes/thub/images/avi.jpg)