- Home /
 
How do I change the compression format of all my texture atlases?
I am trying to change the compression of all my texture atlases to PVRTC_RGBA4 so that I don't have to do them one by one. Here is my code:
                 if( !file.EndsWith( ".meta" ) )
                 {
                     string path = "Assets/Resources/Bundles/" + Path.GetFileName(bundle) + "/Atlases/" + Path.GetFileName(file);
                     tex2D = (Texture2D)Resources.LoadAssetAtPath( path, typeof(Texture2D) );
                     PostprocessTexture( tex2D );
                 }
 
               I get no errors and it pops out what I expect from the last Debug.Log, but it doesn't actually seem to do the compression when I look at the atlas in the inspector. I have also tried using AssetDatabase instead of Resources but that didn't seem to do much of anything.
What am I doing wrong? Or what am I missing?
Answer by chabala · Mar 08, 2013 at 08:08 PM
I figured out my own question. I should have been reimporting the image instead of trying to change the compression on the file. Here is my updated code:
                 if( file.EndsWith( ".png" ) || file.EndsWith( ".tga" ) )
                 {
                     string path = "Assets/Resources/Bundles/" + Path.GetFileName(bundle) + "/Atlases/" + Path.GetFileName(file);
                     tex2D = (Texture2D)AssetDatabase.LoadAssetAtPath( path, typeof(Texture2D) );
                     TextureImporter importer = ( TextureImporter ) TextureImporter.GetAtPath ( path );
                     importer.textureType     = TextureImporterType.Advanced;
                     importer.npotScale         = TextureImporterNPOTScale.None;
                     importer.textureFormat     = TextureImporterFormat.PVRTC_RGBA4;
                     importer.wrapMode        = TextureWrapMode.Clamp;
                     importer.isReadable     = true;
                     importer.mipmapEnabled     = false;
                     importer.maxTextureSize = 4096;
                     
                     AssetDatabase.ImportAsset( path );
                 }
 
              Answer by NeverTrustShadows · Oct 26, 2021 at 01:50 PM
This is no longer valid form of update. Most of the properties are obsolete.
Your answer
 
             Follow this Question
Related Questions
My ios Project is too big!?what can i do? 1 Answer
Calling Resources.Load on a Texture is returning null 1 Answer
Assets aren't found at runtime 1 Answer
Texture Compression format for UWP,Texture 0 Answers
Texture compression distortion. 1 Answer