Search Unity

Preset Manager Filters

Discussion in 'Editor Workflows' started by CDF, Apr 30, 2020.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Just watched this video:

    In 2019.3 we can now define default presets for importers and supply a filter = awesome
    Was wondering what kind of terms the filter can use? I tried using the file extension but that didn't seem to work. Is the filter name only?

    This does not work: preset.png
     
    AlejMC, phobos2077 and Xarbrough like this.
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I still have the same question. The documentation doesn't cover this feature. What queries are supported here? The same as in the project search window I assume, but it could also be anything from wildcards to regex. Also it's not clear if we can use the list for fallbacks, e.g. I was trying to define something like "Music_*" should match the music AudioImporter. If the asset doesn't match, check the next preset in the list, which would be the default AudioImporter that matches any audio clip.
     
    Last edited: Jun 19, 2020
    EZaca likes this.
  3. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    It would be amazing to be able to define folder names as filters. I don't wanna name all my UI textures as xxxxx_ui.png. I just want to keep them in a UI folder with their original name like UI/xxxxx.png
     
    gillemp likes this.
  4. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Any reply on this? Just checked documentation pages for both 2020.2 and 2020.1 and they all outdated. Can I use folder name in filter? Filtering only by asset name would be is completely useless.

    Edit: Nevermind, there is a separate "glob" search functionality added in 2020.1. Still docs need updating.
     
    Last edited: Jun 22, 2020
    Xtro likes this.
  5. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    You can try using it to search the project browser, but look forward to the editor crashing frequently if you mistype things :) Unity needs really document usage of it. If you search glob pattern matching there are other examples with unix / python / java etc...

    one example is this, finding all tga files in folders called Textures

    glob:"*Textures**.tga"

    *EDIT* Figured out more
    To find all textures ending with _N or _n

    glob:"*?(_N|_n).*"

    All png's ending with _NRM or _nrm

    glob:"*?(_NRM|_nrm).png"

    *EDIT* It appears the pattern matching for Preset Manager does work, but only on first-time import into the project, you cannot use Right Click > Reimport and have it apply the newly added filters.

    The way to fix this is to use an AssetPostProcessor, it can find valid default presets using filters from Preset Manager and then you just tell it to apply them. So any existing assets can be updated by just reimporting them.

    Code (CSharp):
    1.  
    2. public class TextureProcessor : AssetPostprocessor
    3. {
    4.     private void OnPreprocessTexture()
    5.     {
    6.         TextureImporter importer = assetImporter as TextureImporter;
    7.         if (importer == null) return;
    8.         //ordered list of presets that set default values when applied to target
    9.         //the presets here are already filtered by preset manager
    10.         Preset[] presets = Preset.GetDefaultPresetsForObject(importer);
    11.         int presetsLength = presets.Length;
    12.         for (int i = 0; i < presetsLength; i++)
    13.         {
    14.             Preset preset = presets[i];
    15.             preset.ApplyTo(importer);
    16.         }
    17.     }
    18. }



     
    Last edited: Jul 31, 2020
    NuclearCookieTF, mitaywalle and CDF like this.
  6. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    Now, that is amazing!

    I can confirm that newly created(imported) textures in any "Sprites" folder in my project are imported with my custom Sprite preset correctly while outside texture are imported with my default texture preset.

    This is my preset settings:

    TextureImporter
    1) no filter = Texture_Default preset
    2) glob:"*Sprites/*" = Sprite_Default preset.

    Adsız.png Adsız.png
     
    cirocontinisio and Xarbrough like this.
  7. jxxxxst

    jxxxxst

    Joined:
    Nov 3, 2012
    Posts:
    50
  8. Vivien_Lynn

    Vivien_Lynn

    Joined:
    May 17, 2019
    Posts:
    19
    I must do something essentially wrong. I have the exact same setup as you:

    upload_2021-3-11_14-34-9.png

    As expected, when I drag and drop a Sprite (*.png) from Windows, anywhere into my Project View, Preset "1" is used.
    But when I drag and drop the Sprite into a folder called "Test", it still uses Preset "1".
     

    Attached Files:

  9. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    Hello.

    What is your Unity version?
    and
    Are you dropping new files to Test folder or are you dropping onto an existing file with the same name? (Second one won't work because, if there is a meta file for the file, it means that it was imported earlier and Unity won't import it again with the Preset 10. If the file exists in Test folder, you need to delete the meta file to force Unity to reimport it with the correct preset.
     
    Vivien_Lynn likes this.
  10. Vivien_Lynn

    Vivien_Lynn

    Joined:
    May 17, 2019
    Posts:
    19
    I am using Unity 2019.4.21f1.
    I have set up the presets like shown above and I created a folder called "Test", which is located somewhere in my project (e.g. Assets/Sprites/Test).

    Now I drag one *.png file from a Windows-folder to the Unity-window and drop it in the folder called "Test" in my project view.
    I tried to use the same sprite multiple times. (Drag and drop it, delete it from the project and try again).
    I also tried to use a completely new sprite with a unique name, without success.
    Both ways prevent the meta-file-issue, am I correct?
     
  11. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    Yes. What you are trying sounds correct.

    If you can reproduce the problem in an empty small project and attach it here as a zip file, I can take a look at it.
    (Don't include these folders to the zip: Library, obj, Temp)
     
  12. Vivien_Lynn

    Vivien_Lynn

    Joined:
    May 17, 2019
    Posts:
    19
    I created a brand-new Project and the problem still persists.
    I set up two presets:
    1. "99" changes the PPU to 99 (Set as Default)
    2. "101" changes the PPU to 101 (Set for glob:"*Test/*")
    I attach the project to this post. (I could not find any folder called "obj" or "Temp", but I did remove "Library")
    Thank you very much for taking your time to look into it.
     

    Attached Files:

  13. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Looks like a problem in 2019 versions.
    Issue doesn't happen in 2020.2
     
    Vivien_Lynn likes this.
  14. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    I can confirm that your setup works fine in Unity 2020.1.15
     
    Vivien_Lynn likes this.
  15. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    Another thing...

    You can use double asterisks at the and to include subfolders to the rule

    glob:"*Test/**"
     
  16. Vivien_Lynn

    Vivien_Lynn

    Joined:
    May 17, 2019
    Posts:
    19
    Because of you two, I also tried 2020.2, and I can confirm that this works. Unfortunate for me, since may current Project uses 2019.
    Thank you two very much for your help!

    This is very useful. What is this syntax called? I would like to read more on these filter settings and how to use them. Sadly the documentation does not give much insight.
     
  17. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    I think it's some form of Regex. I'm not expert on regex but it was easy for me to define the folders and files it in the Unity preset manager.

    We can use this glob regex in Unity project and hierarchy windows too. That's how you can make sure if your filter works fine before using it in the preset manager.
     

    Attached Files:

    Vivien_Lynn likes this.
  18. MilenaRocha

    MilenaRocha

    Joined:
    Jun 30, 2018
    Posts:
    12
    Anyway I can get the preset filter to work with all inherited components?
    E.g: Selectable preset affects button, inputfield,...
     
  19. MilenaRocha

    MilenaRocha

    Joined:
    Jun 30, 2018
    Posts:
    12
    Anyway I can set the depth of that subfolder search? (only 1 subfolder level, or so)
     
  20. AndyBlock

    AndyBlock

    Joined:
    Oct 12, 2016
    Posts:
    35
    I would guess for a single level:

    glob:"*Test/*/*"


    And for two:

    glob:"*Test/*/*/*"

    etc. Not certain, though
     
  21. AlejMC

    AlejMC

    Joined:
    Oct 15, 2013
    Posts:
    149
    How does this exactly work? I can't select make the presets stay, it always goes back to "None (Preset)"
     
  22. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    610
    That's weird. Looks like a bug.
     
  23. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    To reapply default preset to asset eyou need to click Asset -> Inspector/RMB at header/ 'Reset'
     
  24. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    FYI this is STILL the cast in 2023.1.0B11... What a mess

    Happily your script still works though.
     
  25. irfanbaysal1997

    irfanbaysal1997

    Joined:
    Sep 17, 2018
    Posts:
    6
    I can find the prefab on console with the same filter string however cannot apply it from Preset Manager
     

    Attached Files:

  26. Tortuap

    Tortuap

    Joined:
    Dec 4, 2013
    Posts:
    137
    But has anyone reported this bug ? It won't correct by itself...
     
  27. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    108
    As much as I hate Unity's bugs, I don't think this is one. Reimport is not supposed to apply new filters. It would be a disaster if it does. Reimport should reimport the assets with whatever settings in .meta files.
     
    LookingGlassTeam likes this.