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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to go from TextureImporterFormat to TextureFormat?

Discussion in 'Scripting' started by Steven-1, May 14, 2015.

  1. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    451
    In short; I need to get the corresponding TextureFormat for any TextureImporterFormat.

    I'm writing an AssetPostprocessor;
    in the OnPostprocessTexture(Texture2D texture) function I want to compress the texture in the textureformat defined in the editor (in the TextureImporter), like it would if I didn't do anything in this function.

    However, the compression function (EditorUtility.CompressTexture()) expects the format to be of type TextureFormat, but the only format I can get is of type TextureImporterFormat.

    How do I get from the one to the other?

    Or how can I avoid this problem alltogether?

    I'm doing it manually now, which is a pain the ass. especially since it differs depending on the version of Unity, which also means it could change with any new Unity update. :(
     
  2. duotemplar

    duotemplar

    Joined:
    Dec 30, 2010
    Posts:
    26
    You can use TextureImporter to import the asset, don't use EditorUtility.CompressTexture()
     
  3. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    451
    I don't think you understand the case;
    I don't want to reimport the texture, I want to compress it.
    What I'm writing happens right after a texture is imported, so letting it then reimport the texture again is completely useless.

    Unless Im misunderstanding you?
     
  4. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    451
    Now it appears the entire EditorUtility.CompressTexture() function no longer works (throws an error),
    which means the manual fix I made no longer works as well (as I just can't do any compression now).

    I reported it as a bug, but I got no response.

    I really need this to work, so a reply from Unity or someone else who knows something about this would be much appreciated.