Search Unity

Building both compressed and uncompressed AssetBundles

Discussion in 'Asset Bundles' started by FromTheFuture, Jun 4, 2019.

  1. FromTheFuture

    FromTheFuture

    Joined:
    Jul 25, 2012
    Posts:
    57
    Hello,

    Because Android can not currently play videos from compressed AssetBundles, I need to produce a mix of both compressed and uncompressed bundles, currently in an editor script.

    My approach was to first build them all with compression:
    Code (CSharp):
    1. AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(AssetBundleDirectory, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
    And then make another pass finding the video bundles, deleting them (just in case), and create them directly again, but specifying uncompressed:
    Code (CSharp):
    1. AssetBundleBuild buildMap = new AssetBundleBuild
    2. {
    3.     assetBundleName = assetBundleName,
    4.     assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName)
    5. };
    6.  
    7. //Try deleting the files first, even though we are specifying the force rebuild flag
    8. //it seems to produce a bundle that is still compressed.
    9. string fullName = Path.Combine(AssetBundleDirectory, assetBundleName);
    10. Log($"     Deleting bundle first: {fullName}");
    11. Log($"       Exists: {File.Exists(fullName)}");
    12. File.Delete(fullName);
    13. Log($"       After Delete: {File.Exists(fullName)}");
    14. fullName += ".manifest";
    15. Log($"     Deleting manifest: {fullName}");
    16. Log($"       Exists: {File.Exists(fullName)}");
    17. File.Delete(fullName);
    18. Log($"       After Delete: {File.Exists(fullName)}");
    19.  
    20. Log("     Building bundle w/o compression...");
    21. Log($"       Map bundle name: {buildMap.assetBundleName}");
    22. AssetBundleBuild[] fullMap = new AssetBundleBuild[1];
    23. fullMap[0] = buildMap;
    24. var uncompressedManifest = BuildPipeline.BuildAssetBundles(AssetBundleDirectory, fullMap, BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.ForceRebuildAssetBundle, EditorUserBuildSettings.activeBuildTarget);
    It will create those video bundles again, but they are still compressed, seemingly ignoring the flags passed to BuildAssetBundles.

    Any thoughts? Thanks!
     
  2. FromTheFuture

    FromTheFuture

    Joined:
    Jul 25, 2012
    Posts:
    57
    Should have mentioned: 2018.4.0f1
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    If building the bundles doesn't take too long, then I personally would keep it simple:
    1) Build all bundles uncompressed.
    2) Build all bundles compressed.
    3) Do replacements.

    Also, videos don't need to be in Asset Bundles. You can play a video straight from a URL.
     
  4. FromTheFuture

    FromTheFuture

    Joined:
    Jul 25, 2012
    Posts:
    57
    Howdy, thanks for the reply!

    The bundles are fairly big, if I could avoid building them all twice, I'd prefer it. But my bigger concern - either with your proposal or my current scheme: why did Unity fail to produce an uncompressed asset bundle after producing a compressed one, even though the previous one was deleted. Is there a cache somewhere that is affecting this?

    I also could avoid video Asset Bundles as you suggest, but it would require a bit of a retooling as we already have a functioning system for versioning and delivering Asset Bundles. If this is just a cache I could clear, or another step I could take to allow this current workaround to work, it would be considerably less effort.

    Thanks!
     
  5. fmarianacci

    fmarianacci

    Joined:
    Oct 15, 2018
    Posts:
    20
    Same problem here.

    I use the uncompress flag. But it doesn't work. But it is weird because it work well the last 3 months...

    The only difference I found is the size of the bundle, it work when it's under 9Go and it doesn't work when it's greater 9Go. Maybe a assetbundle greater than 9go cannot be build uncompress ?

    @FromTheFuture how big is your bundle ?

    Project in 2018.4f.0
     
    Last edited: Aug 1, 2019