Preset Manager Filters

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:

3 Likes

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.

1 Like

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

1 Like

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.

1 Like

You can try using it to search the project browser, but look forward to the editor crashing frequently if you mistype things :slight_smile: 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.

public class TextureProcessor : AssetPostprocessor
{
    private void OnPreprocessTexture()
    {
        TextureImporter importer = assetImporter as TextureImporter;
        if (importer == null) return;
        //ordered list of presets that set default values when applied to target
        //the presets here are already filtered by preset manager
        Preset[] presets = Preset.GetDefaultPresetsForObject(importer);
        int presetsLength = presets.Length;
        for (int i = 0; i < presetsLength; i++)
        {
            Preset preset = presets[i];
            preset.ApplyTo(importer);
        }
    }
}
3 Likes

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.

2 Likes

Seems like 2019 cannot use glob filtering but it can use filename filtering as stated in this blogpost :
https://blogs.unity3d.com/2019/10/11/improve-workflows-validate-decisions-and-avoid-errors-with-presets/

I must do something essentially wrong. I have the exact same setup as you:

6924419--812555--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”.

6924419--812552--upload_2021-3-11_14-33-38.png

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.

1 Like

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?

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)

I created a brand-new Project and the problem still persists.
I set up two presets:

  • “99” changes the PPU to 99 (Set as Default)

  • “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.

6929090–813260–Preset Filter Test.zip (32.3 KB)

Looks like a problem in 2019 versions.
Issue doesn’t happen in 2020.2

1 Like

I can confirm that your setup works fine in Unity 2020.1.15

1 Like

Another thing…

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

glob:“*Test/**”

4 Likes

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.

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.

6929285--813287--upload_2021-3-12_11-18-9.png

1 Like

Anyway I can get the preset filter to work with all inherited components?
E.g: Selectable preset affects button, inputfield,…

Anyway I can set the depth of that subfolder search? (only 1 subfolder level, or so)

I would guess for a single level:

glob:“Test//*”

And for two:

glob:“Test///

etc. Not certain, though