Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Changing addressable groups compression

Discussion in 'Addressables' started by nargesMMT, Mar 23, 2022.

  1. nargesMMT

    nargesMMT

    Joined:
    Nov 11, 2021
    Posts:
    2
    Hi,
    I'm new to addressables and I'm not sure if I understood addressable schemas...
    I want to change the "Asset Bundle Compression" of my addressable groups before building the game (in script) (I want to have different compression types for different platforms)

    Is this even possible?

    From what I found, I should add an BundledAssetGroupSchema to the schemas list from my addressableAssetGroup...

    something like this:
    Code (CSharp):
    1. BundledAssetGroupSchema bundledAssetGroupSchema = new BundledAssetGroupSchema();
    2. bundledAssetGroupSchema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4;
    3.  
    4. aag.Schemas.Add(bundledAssetGroupSchema);
    Is this right? I don't understand why an AddressableAssetGroup can have multiple schemas, and which one is finally applied?!
     
  2. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    93
    We've taken the easiest path and just iterated through all groups and modified their schema depending on the target platform requirements before building player content:

    Code (CSharp):
    1. foreach (var addressableAssetGroup in UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings.groups)
    2. {
    3.     var groupSchema = addressableAssetGroup.GetSchema<BundledAssetGroupSchema>();
    4.  
    5.     if (groupSchema != null)
    6.     {
    7.         // Whatever compression setting is needed
    8.         groupSchema.Compression = BundledAssetGroupSchema.BundleCompressionMode.Uncompressed;
    9.     }
    10. }
    11.  
    12. UnityEditor.AddressableAssets.Settings.AddressableAssetSettings.BuildPlayerContent();
     
    celikomerdev likes this.
  3. massiveminiteam

    massiveminiteam

    Joined:
    Aug 28, 2018
    Posts:
    109
    Thanks @einWikinger
    I did almost the same thing, forgot to update this thread