Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DoktorAce · Dec 03, 2012 at 02:23 PM · editortexture2donpostprocesstexture

Compressing in OnPostprocessTexture yields "Not yet compressed"

I'm trying to create an editor script that can take a selected texture of any compression setting, manipulate it, and then compress it again. This becomes a problem since I have to set the selected texture to a format that can be edited (SetPixels), like RGBA32, etc.

The result works, but Unity tells me that the texture is "Not yet compressed" when I later select it. It IS however compressed when I look at its size when using it on the scene.

Does anyone have an explanation for this? Is it just the Unity Editor thats plain wrong? Or am I doing something wrong?

This is a pseudo-version of my editor extension:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 using System.Collections.Generic;
 
 public static class TextureManiplator  {
     public static List<Job> Jobs = new List<Job>();    
     
     [System.Serializable]
     public class Job {
         public string TargetPath;
         public Color TargetColor;
         public TextureImporterSettings OriginalTextureSettings;
         public TextureFormat OriginalTextureFormat;
     }
     
     public static void CreateJob(Texture2D texture, Color color) {
         // Create and save job
         var j = new Job();
         j.TargetPath = AssetDatabase.GetAssetPath(texture);
         j.TargetColor = color;
         j.OriginalTextureFormat = texture.format;
         Jobs.Add(j);
         
         AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(texture)); // Force texture to reimport
     }
     
     [MenuItem("Texture Manipulator/Red")]
     public static void Menu_Red() {
         foreach (Texture2D texture in Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets)) {
             CreateJob(texture, Color.red);
         }
     }
     
     class Postprocessing : AssetPostprocessor {
         
         void OnPreprocessTexture() {
             foreach(TextureManiplator.Job j in TextureManiplator.Jobs) {
                 if(j.TargetPath == assetPath) {
                     var importer = assetImporter as TextureImporter;
                     
                     // Save original settings
                     j.OriginalTextureSettings = new TextureImporterSettings();
                     importer.ReadTextureSettings(j.OriginalTextureSettings);
                     
                     // Make sure the texture is readable
                     importer.textureFormat = TextureImporterFormat.ARGB32;
                     importer.isReadable = true;
                 }    
             }
         }
         
         void OnPostprocessTexture (Texture2D texture) {
             foreach(TextureManiplator.Job j in TextureManiplator.Jobs) {
                 if(j.TargetPath == assetPath) {
                     
                     // Mess with colors (This is not what I'm actually doing, but its not important
                      for (var m = 0; m < texture.mipmapCount; m++) {
                         var c = texture.GetPixels(m);
                         for (var i = 0 ;i < c.Length; i++) {
                             c = j.TargetColor;
                         }
                         texture.SetPixels(c, m);
                     }
                     
                     // Restore original settings
                     var importer = assetImporter as TextureImporter;
                     importer.SetTextureSettings(j.OriginalTextureSettings);
                                     
                     // Apply and Compress texture
                     texture.Apply(false, j.OriginalTextureSettings.readable);
                     EditorUtility.CompressTexture(texture, j.OriginalTextureFormat, j.OriginalTextureSettings.compressionQuality);
 
                     
                     TextureManiplator.Jobs.Remove(j); //Remove job
                     return;
                 }
                 
             }
         }
         
     }
     
 }
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image logick · Jul 10, 2015 at 10:35 PM 0
Share

I am currently dealing with this now in unity 4.6. Was a solution found?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tutanhomon · May 02, 2014 at 12:32 PM

you must go to preferences and check "Compress assets on import" checkbox, this will cause assets reimport and all textures will be comressed, showing their compressed size instead of "Not yet compressed" message.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Load image onto a Plane in the editor using C# 0 Answers

Graphics.DrawTexture in OnPostprocessTexture 1 Answer

texture2d field in a custom editor window 3 Answers

EditorWindow loses Texture2D reference on scene change: how to handle? 4 Answers

Make a PropertyField() for a Texture2D SerializedProperty looking like an ObjectField() 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges