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
  4. Dismiss Notice

Texture importer preset not working for platform specific options

Discussion in 'Editor & General Support' started by Deleted User, Sep 9, 2019.

  1. Deleted User

    Deleted User

    Guest

    Unity 2018.4.2f1 and macOS 10.14.5
    I'm setting up presets for different formats (audio, fbx, texture...) and run into a possible issue with the texture importer preset.

    If I add platform specific settings to a texture importer preset, it seems like they are not applied when I assign the preset to a texture.

    For example: I have different texture sizes, formats and compressions for iOS, Android and WebGL. The values I have set to the preset are not applied when I use the preset.

    Has anyone else noticed this?
     
    andreiagmu likes this.
  2. andreiagmu

    andreiagmu

    Joined:
    Feb 20, 2014
    Posts:
    172
    I'm having the same issue on Unity 2019.3.0b5.
    Have you reported this bug to Unity's issue tracker?
     
  3. andreiagmu

    andreiagmu

    Joined:
    Feb 20, 2014
    Posts:
    172
    To be more specific, I'm having a series of issues with texture importer presets on my end, including the issue mentioned by @JyriKilpelainen:

    - In Unity Editor, if I try to change any of the Import Settings (Max Size, Resize Algorithm, Compression, etc.) in my preset asset, the new values aren't applied to the preset. If I deselect the preset and select it again, the old values are back. It's like they are being frozen by something.
    The other Texture settings (Texture Type, Advanced settings, Wrap Mode, etc.) aren't affected by this issue.

    I discovered a workaround for this issue, by closing Unity and directly editing the .preset file in a text editor. I'll describe it in a moment.

    - If I apply that preset to a texture, the overrides for platforms enabled in the project aren't applied. Same issue as JyriKilpelainen, from what I understood.
    But, strangely, it seems that the overrides for platforms not present in the project are applied.

    For example, my project is built only for Standalone and Android platforms. In my preset file, I had overriden the texture importer's Max Size property to 256, for Android and iOS (I may build the project for iOS in the future).

    In my case, I could only make those overrides by closing Unity, then opening the .preset file inside a text editor, and for each platform, directly setting the value "256" on the respective property m_PlatformSettings.Array.data[n].m_MaxTextureSize.
    I also set the property m_PlatformSettings.Array.data[n].m_Overridden to 1 (true), without this, the preset override wouldn't load inside Unity.

    After opening Unity, the .preset asset is correctly overriden, the override for Android shows up at the Inspector tab (while the .preset asset is selected). It actually works as the default Texture Importer preset if I set it as the default one, so when I add a new texture to my project, the overrides are correctly applied.

    texture inspector 2.png
    My preset's inspector.

    If I select that same preset to an existing texture (and hit the Apply button), it doesn't apply the Max Texture override for Android. In the texture's inspector (that shows the texture importer tabs for Default, Standalone and Android in my project), the "Override for Android" checkbox isn't even checked. o_O

    texture inspector.png
    My existing texture's inspector. At this point, "Override for Android" should've been checked, and Max Size should've been 256, just like in my preset asset.

    However, if I open my existing texture inside a text editor (or even better, if I make a diff inside a version control system, to see if there were any changes in the file), I can see that the Max Texture override (256) I set up for iOS was applied to the texture! (including the "overriden = true" property)
    And remember, in my project I don't have iOS platform enabled. And I can bet that override wouldn't work if I had iOS platform enabled and its respective tab appearing on my Inspector. :confused:

    It's a strange behaviour indeed...
     
  4. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,081
    (Case 1213149)
     
    fffMalzbier likes this.
  5. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    178
    Hi there!

    Yes, that problem is known on our end and is not related with Presets directly (because applying from script or changing the values outside of the inspector is working as expected)
    We are currently looking at refactoring the setting platform part of the TextureImporter inspector so it works better with Presets and stops reverting the changes every frame (This is what happening at the moment, which we know is very painful...)
    Until then, it is still possible to edit the texture importer asset directly and save the changes back to the Preset. Using the PresetManager to apply them by default should always work. Also, writing a simple script that would apply the Preset to your textures using preset.ApplyTo method should work as a workaround until the proper UI fixes are done.
     
    firstuser, fffMalzbier and JesOb like this.
  6. cooloon

    cooloon

    Joined:
    Nov 25, 2014
    Posts:
    10
    Hi, this issue still exists in Unity 2019.4.0 and do you have any plan to fix?
     
  7. GuerricHache

    GuerricHache

    Joined:
    Dec 21, 2013
    Posts:
    9
    I'm running up against this as well. I'm happy to edit the file myself, but andreiagmu's comment above only tells me how to change the m_MaxTextureSize property. I want to change the Compression property, which seems to be 0, and I'm not sure what it should be (I want "None" in the editor).

    I tried setting it to 1 just to see what happened, and then the editor started complaining about the Format not being valid for my platform.

    Also, the preset's file format is very iffy - Notepad++ fills it with a ton of "null" symbols, and doesn't have any newlines or whitespace, so it's a mess to edit. Is there a better way to view it?
     
  8. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    178
    Compression values are defined here: https://github.com/Unity-Technologi...no/AssetPipeline/TextureImporterEnums.cs#L319
    But this is also dependent upon the format, some of them are compressed and others not, the list of existing formats are defined in the same file at line 33.

    I would suggest setting the per-platform settings directly on a texture and then create a Preset from it instead of editing the Preset directly until we figure out a solution to make it work properly in the Preset UI.
     
  9. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    If you prefer the behaviour of presets always being enforced you can use this code, when changing a non-excluded property it will be enforced when hitting apply (as the texture runs through the asset post processor). If you need to quickly apply a changed preset to the entire project or subfolder you can right click in project view and select reimport & it will apply the preset or enforce it.
    It would be better if Unity added this functionality to the Preset Manager, a checkbox for "Strictly Enforce" and a button for "Apply Preset Project-Wide", maybe with a "Caution, this may take a while depending on the number of assets in the project" confirmation.

    ***EDIT*** I should note that if you go this route, be aware that presets overwrite hidden properties like m_UserData You could first Exclude all properties from the right click context menu in the preset inspector, but this would also remove the texture max size properties.

    So really, Unity should hopefully provide a better inspector for editing presets that exposes all the properties that are in meta files.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Presets;
    3.  
    4. namespace AssetImporterPreset
    5. {
    6.     internal static class AssetImporterPreset<T> where T : AssetImporter
    7.     {
    8.         internal static void ApplyFilteredPresets( T importer )
    9.         {
    10.             if (importer == null) return;
    11.             //ordered list of presets that set default values when applied to target
    12.             //the presets here are already filtered by preset manager
    13.             Preset[] presets = Preset.GetDefaultPresetsForObject(importer);
    14.             int presetsLength = presets.Length;
    15.             for (int i = 0; i < presetsLength; i++)
    16.             {
    17.                 Preset preset = presets[i];
    18.                 preset.ApplyTo(importer);
    19.             }
    20.         }
    21.     }
    22. }
    And a Texture post processor making use of it

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. namespace AssetImporterPreset.Texture
    4. {
    5.     internal class TextureProcessor : AssetPostprocessor
    6.     {
    7.         private void OnPreprocessTexture()
    8.         {
    9.             TextureImporter importer = assetImporter as TextureImporter;
    10.             AssetImporterPreset<TextureImporter>.ApplyFilteredPresets(importer);
    11.         }
    12.     }
    13. }
     
    Last edited: Aug 12, 2020
  10. ColinDarkwind

    ColinDarkwind

    Joined:
    Nov 26, 2013
    Posts:
    8
    This is still an issue in 2020.1, and we're coming up on a year since it was mentioned in this forum post. I couldn't find an issue tracker for the issue (even with the case number mentioned above) but since it's known on your end, maybe we could get a status update? This is a pretty painful issue and kind of trashes our confidence in using presets in our pipeline.

    I'd be happy to write up an issue if needed.
     
    Hoorza, Jde, hessel_mm and 2 others like this.
  11. Jde

    Jde

    Joined:
    Oct 2, 2011
    Posts:
    139
    I'd also like to be able to use presets for setting default texture compression in our current project. This bug is preventing us from doing that. Any news on the status of this?

    Alternatively, I'd like to be able to change the default compression format (when not using the platform override) from PVRTC to ASTC on iOS. We don't plan to support anything below the A8 chip, so we'll have no need for PVRTC. Is that possible?
     
  12. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Same issue here. Just noticed that it wasn't working and this is very important for many of our textures.
     
  13. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    178
    Hey everyone!
    Issues between Presets and TextureImporter per-platform settings are fixed in the following versions: 2019.4.12 release, 2020.1.7 release, latest 2020.2 beta, and 2021.1 alpha.
    We had two issues related to that, that are both fixed in the mentioned version:
    https://issuetracker.unity3d.com/issues/presets-dont-record-per-platform-settings
    https://issuetracker.unity3d.com/is...esetting-import-settings-or-applying-a-preset

    Unfortunately, we don't have that granularity for platform settings at the moment. The override mechanism decides that all of the per-platform are overridden or none of them. We are aware of such limitations and are working to fix them, but that requires a lot of changes in the import system which takes some time to get there.
    However, you should be able to manually enforce this import setting using the OnPreprocessTexture method (https://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPreprocessTexture.html). Look at the current platform and compression, and if you see the setting is PVRT you can enforce it to ASTC.
     
    Ziflin likes this.
  14. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,011
    On Android you can globally override the texture compression format from the build settings. Why isn't something similar possible for iOS? I don't understand.

    The current "solution" requires overriding by script each and every texture, creating a whole bunch of versioning noise every time I go back and forth between pvrtc and astc.

    In general I don't know who thought it would be a good idea to be able to mix and match different formats in the same project, but made it impossible to globally say "Hey, I think I want to use ASTC for this project".
     
    NintenjoSumo and JesOb like this.
  15. NintenjoSumo

    NintenjoSumo

    Joined:
    Nov 20, 2020
    Posts:
    2
    I agree..makes project structuring and builds incredibly hard to track when dealing with a broad range of mobile devices, platforms and overrides.
     
  16. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    414
    I'm working in Unity 2021.1.22f1 and can confirm this issue still occurs in that version.
     
  17. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    492
    I am on Unity 2021.3.11 and seems have same issue. My Import Profiles doesn't work at all.
    Did someone solve it?
     
  18. Nintenjo64

    Nintenjo64

    Joined:
    May 19, 2015
    Posts:
    12
    I am using 2021.3.19f1 and still the import preset manager settings are only 'partially' applied to any new assets it catches. Any texture setting overrides such as Max Size, Alogorithm, Format and Compression are all ignored. If you select an asset and apply the preset again manually it will then make update the settings stored in the preset manager. This is very easy to reproduce and pretty poor its not been fixed by now :(
     
  19. FairyMental

    FairyMental

    Joined:
    Apr 26, 2016
    Posts:
    5
    Unity 2021.3.22 - Stiiiiill happening... And guess who has over 500 textures!
     
  20. JokerDen

    JokerDen

    Joined:
    Apr 9, 2015
    Posts:
    9
    Confirm, my TextureImporter doesn't work on 2021 LTS for platform override.