Search Unity

Texture compression override in Android build settings

Discussion in 'Unity Build Automation' started by greenalice, Oct 13, 2014.

  1. greenalice

    greenalice

    Joined:
    May 16, 2014
    Posts:
    13
    Is it possible to somehow specify the texture compression override when making a build for Android in UCB?
     
  2. greenalice

    greenalice

    Joined:
    May 16, 2014
    Posts:
    13
    Anyone?
     
  3. hypeNate

    hypeNate

    Unity Technologies

    Joined:
    Apr 4, 2014
    Posts:
    272
  4. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @greenalice I'm not sure what you think of, but the used texture compression is stored in the meta files and UCB should use the configurations of the meta files for importing the texture compression. I haven't put an eye on that yet, but I doubt that all textures are imported in 32bit for mobile apps, when they are configured different in the meta files. Would mean a huge impact on memory usage and should be easy to test.
     
  5. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    I know I'm late to the party but if anyone needs this today, this will work in UCB as well:
    Code (CSharp):
    1.  
    2. public void OnPreprocessBuild(BuildReport report)
    3.  {
    4. #if UNITY_ANDROID
    5.         EditorUserBuildSettings.androidBuildType = AndroidBuildType.Release;
    6.         EditorUserBuildSettings.buildScriptsOnly = false;
    7.         EditorUserBuildSettings.allowDebugging = false;
    8.         EditorUserBuildSettings.androidBuildSubtarget = MobileTextureSubtarget.ETC;
    9. #if HIGH_QUALITY_32
    10.         EditorUserBuildSettings.androidETC2Fallback = AndroidETC2Fallback.Quality32Bit;
    11. #else
    12.         EditorUserBuildSettings.androidETC2Fallback = AndroidETC2Fallback.Quality16Bit;
    13. #endif
    14. #endif
    15. }
    16.  
     
    solarisn and LilGames like this.
  6. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Is this still true? We're trying to figure out why Build Settings for texture compression seems to have no effect, and UCB has no such settings in its Android config options.
     
  7. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    I confirm this is still true, it has no effect when changed in the editor, once building in UCB. You need to use the code I sent here the other day; I use this, and it works correctly ;)
     
    LilGames likes this.
  8. victorw

    victorw

    Joined:
    Sep 14, 2016
    Posts:
    459
    Have you configured the Android texture compressions separately (requires installing Android build support locally)? Also would be interested to know whether running a clean build changes anything. I don't think there's any reason that UCB should be interacting with these settings but it's possible that the build process is polluting the cache somehow, running a clean build should bypass that and help me diagnose why this is happening.
     
  9. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    On my side, I have the project opened locally, setup the texture compression for Android correctly, committed everything and pushed, did clean builds, it doesn't change anything, for UCB, texture override remains at "No override" for me.

    Having the code setup the override doesn't require a clean build to have it work. For me there is no other solution than this and works fine. I tried everything, and nothing else worked.

    To my knowledge this parameter should be stored in EditorBuildSettings.asset file. When I change it to a different texture compression and commit the change, it's simply ignored by UCB.

    My guess is they ignore this file as they use custom scene list, and other settings of this file can be override by UCB (AAB, Deb build etc.) and texture compression must be ignored too for some reason, even if we don't have a drop-down yet to override it in UCB.

    Cheers,
    Charles.
     
  10. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    Sorry I didn't see you were UT. Could you confirm to use in which file this setting is stored please? This way I'll check if for some reason it's ignored by mistake. It's indeed setup as an override in the project, but I think this texture compression issue happens also when I open a fresh clone of my project (reverts to No override). This is why maybe we are ignoring a file we shouldn't. But EditorBuildSettings.asset is no longer ignored in our project (it was because scene list is usually something we don't want to commit and push).

    Maybe having it ignored before and now present still somehow reverts to No Override.
     
  11. victorw

    victorw

    Joined:
    Sep 14, 2016
    Posts:
    459
    If you have your Asset Serialization set to Force Text then the EditorBuildSettings.asset should be relatively human-readable, you could take a look to see if there's any setting that looks relevant. From what I can see there is no change to this file when changing the Android ETC2 settings in the Build Settings window, so the setting is only stored in the cache and does not make it into source control. If a fresh checkout of the project generates the same results as UCB then that seems very likely to be the case.

    I'm not a Graphics or Android team dev but it looks to me that if you modify the textures individually then that will be uploaded to source control HOWEVER build settings window changes only apply to your local machine. I'm currently checking in to see whether this is expected behavior or should be filed as a bug.
     
    Last edited: Apr 13, 2020
  12. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    189
    Thanks for this info and for looking into it!

    Yes, OK. Well this current behavior is no big deal, but a bit annoying when you:
    - Open a fresh new cloned repo of a project: you must not forget to change this and it greatly increases import time again by reimporting everything (this isn't great, I'm a Unity Pro power user for years and sometimes forget this)
    - UCB doesn't use the same as your "local build machine": you expect that if you setup everything and push you'd have the same results from a UCB build (except for Android settings on UCB that you change manually)

    However, I guess if this shouldn't change and shouldn't be stored in the files in the repo and remain like this, then UCB for Android should have this setting available to configure along with AAB and dev builds checkboxes and scenes list, as right now there is no way to ensure a UCB build has the same setup as a local build. It would then make sense to have it default to "No Override" until you change it.

    As it is now, you can't know about this until you upload to Google Play and it shows you that you don't have the same OpenGL textures as previous builds.

    Thanks,
    Charles
     
    FeedMyData likes this.
  13. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    I can confirm that the build settings set to "ETC2" locally are ignored in UCB. We had to resort to haze's excellent preprocess solution and our APK now got knocked down from >200mb to <100mb ! YES!!!

    (Unity 2018.x latest)
     
  14. victorw

    victorw

    Joined:
    Sep 14, 2016
    Posts:
    459
    So to confirm, you are configuring the texture to use ETC2 on the texture itself? Or are you configuring it via the build settings window?
     
  15. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Configured in BUILD SETTINGS under Android. Textures are set to default with NO individual overrides.

    Something just occurred to me. Is it possible that setting the "Texture Compression" setting in Build Settings, doesn't get passed to UCB unless I then "Switch Platform" first? (Maybe you two have discussed this already. I admit I only skimmed the subsequent responses between you and haze)
     
  16. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
  17. victorw

    victorw

    Joined:
    Sep 14, 2016
    Posts:
    459
    No - virtually nothing in the build settings window gets saved anywhere other than to your local machine. The build settings window is intended to be used for the creation of one-off builds.

    If you want to ensure that texture compression is consistent then the correct way to do it is to set it on each texture. It's obviously pretty cumbersome but it's the only way to make sure all your builds are consistent (if I was doing that myself I would probably write a plugin to iterate all the textures in project and push the correct settings for each).
     
    LilGames likes this.
  18. MikeSz

    MikeSz

    Joined:
    Jul 7, 2014
    Posts:
    31
    Ok, we just got hit by it as well

    For the life of me - I just can't fathom the logic behind this

    There is a "master override" for texture compression that is a super useful thing (our example: 1920x1080 backgrounds on Android. They will be not compressed by default, as they are RGB with no Alpha so ETC1 is default and ETC1 does not work with NPOT textures, so it fallbacks to... RGBA8 uncompressed... It's 5.7 vs 1.0 MB size...) that only makes sens if it is a project setting yet it is not

    This makes 0, null, nada, zero, no damned sense

    Yes. You can go around this limitation by doing it on a per texture basis, but then you are ignoring the fact that most assets are usually set once for all platforms, not per platform basis

    Why is this like this?
    It's 2020 and when ALL devices released for last several years support ETC2 default fallback for RGB NPOT textures is... uncompressed RGBA8 which is just the worst possible choice out there?

    At least enable this as a master override for project, not per user, this is a team work after all
     
    Rabadash8820, mikerz1985 and LilGames like this.