Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Exclude some asset bundles from mobile

Discussion in 'Asset Bundles' started by Dezaos111111, Sep 17, 2019.

  1. Dezaos111111

    Dezaos111111

    Joined:
    Sep 17, 2019
    Posts:
    2
    The game I'm working on is being ported to mobile, and we want to exclude some of the asset bundles when we build to mobile, is this possible? Maybe using bundle variants somehow? I couldn't find a post that specifically answers this question, so any help would be much appreciated. We are using Unity 2018.3.
     
  2. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    I have a similar case, not sure if there is a better approach but in my case I made a simple tool that detects all the asset bundle names defined in the project. Then I make a few bools per bundle name to determine if that bundle should or should not be exported in the different platforms (find picture attached as example).

    Then I have a button to generate the bundles per platform, this code should help a bit:
    Code (CSharp):
    1. List<string> osxBundles = new List<string>();
    2.  
    3.             for (int i = 0; i < m_BundleNames.Count; i++)
    4.             {
    5.                 string bundle = m_BundleNames[i];
    6.  
    7.                 if (m_BundlesOSX[bundle])
    8.                     osxBundles.Add(bundle);
    9.             }
    10.  
    11.             Debug.Log("Number of asset bundles for OSX: " + osxBundles.Count);
    12.             AssetBundleBuild[] builds = new AssetBundleBuild[osxBundles.Count];
    13.  
    14.             for (int i = 0; i < osxBundles.Count; i++)
    15.             {
    16.                 builds[i].assetBundleName = osxBundles[i];
    17.                 builds[i].assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(osxBundles[i]);
    18.             }
    19.  
    20.             BuildPipeline.BuildAssetBundles(m_PathOSX, builds, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneOSX);
    21.  
    22.             AssetDatabase.Refresh();
     

    Attached Files:

  3. Dezaos111111

    Dezaos111111

    Joined:
    Sep 17, 2019
    Posts:
    2
    How fast it that approach? Because we have alot of assets.