Search Unity

Unity preset manager filter

Discussion in 'Editor Workflows' started by theCodeHermit, Mar 7, 2022.

  1. theCodeHermit

    theCodeHermit

    Joined:
    Sep 20, 2018
    Posts:
    39
    I have made specific presets for textures like Normal or Emission maps. After they are imported I have to manually select each one and assign the proper preset.

    I want to automate this process. To do this Unity has preset filters:

    https://docs.unity3d.com/Manual/class-PresetManager.html

    The problem is I cant get the syntax to work. I have tried so many variations of the documentation examples, but nothing works.

    Example:

    Lets say I want every png file which ends in "_Normal" to get a specific preset value.

    ssd.png
     
    irfanbaysal1997 likes this.
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Your example would be:
    glob:"*_normal.png"


    I confirmed this to work in my project. However, also be aware that Unity presets are only applied for assets which don't yet have import settings, or said differently, only the very first time it is imported. That would mean, if you rename an asset or change the assigned preset, you cannot expect the settings to be applied automatically, even if you context-click and reimport an asset. Instead, you have to apply the preset manually in this case, and to test the automatic preset manager assignment, delete a test asset and add a new one.
     
  3. theCodeHermit

    theCodeHermit

    Joined:
    Sep 20, 2018
    Posts:
    39
    Thanks allot ! You saved me allot of headaches.
    Yeah I know it works only on import.
    Btw how did you figure that syntax out ? Did you look at my link from above ? Or is there some other place I can check how the syntax works (whatever it is even called) ?
     
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Glad it works!

    Yes I did, since there's no way I could remember these things. It says in the docs to use the asterisk symbol to match 0 or more characters. Whereas the angled brackets indicate a range of characters (with a really weird syntax honestly). But don't worry if you had trouble figuring it out, it's unintuitive stuff and hard to test within Unity.

    You can think of it like placeholder characters: *_normal.png means, replace the asterisk with any or no character, and it will match. So "MyTex_normal.png" is a match, but "MyTexnormal.png" is not. Even "_normal.png" is a match, but "_Normal.png" is not because its case-sensitive.

    Yes, you could look up how Regex works, and get acqainted with it via online regex testers (just search, any will do). There you can input text and edit your search patterns with live feedback. Of course, Regex is not Glob and Unity most likely has a custom implementation of what they call Glob here. So you could also look up a tutorial on Glob syntax in general. In any case, it will help understand the basic principles of how these matches work and then you can come back to Unity and discover more easily how Unity implements the rules (always be aware that they might be a little different).

    If you have more specific questions, feel free to ask, I might be able to explain how it works knowing how confusing it can be.
     
  5. theCodeHermit

    theCodeHermit

    Joined:
    Sep 20, 2018
    Posts:
    39
    Aha I see. Yeah it is really unintuitive. The online regex thing is a good idea though. It would be useful If I get stuck on smth like that in the future.
    Anyway thanks again for the help !
     
  6. liudgervr

    liudgervr

    Joined:
    May 5, 2021
    Posts:
    3
    You can rerun the preset by using reset on the file.

    upload_2023-1-10_18-52-39.png

    The only problem I have is that Untity has indeed his own implementation on glob :(
    When I test on this tester it works but Unity glob doesn't.
    https://www.digitalocean.com/community/tools/glob?comments=true&glob=*[Aa]ccessory_*_[Dd]*.[TtPp][GgSs][AaDd]&matches=false&tests=// This will match as it ends with '.js'&tests=/hello/world.js&tests=Tex_Accessory_M_Glasses_Round_Tortoiseshell_D_R.tga&tests=// This won't match!&tests=/test/some/globs
    glob = *[Aa]ccessory_*_[Dd]*.[TtPp][GgSs][AaDd]
    test string = Tex_Accessory_M_Glasses_Round_Tortoiseshell_D_R.tga

    Is there any other way to do these preset without building your own tool?
     
    Last edited: Jan 10, 2023
  7. irfanbaysal1997

    irfanbaysal1997

    Joined:
    Sep 17, 2018
    Posts:
    6

    I have also same issue.
    https://forum.unity.com/threads/preset-manager-filter.1467914/
    How can I solve it?