# 4. AssetPostprocessor Folder Rules
Part of [[Asset Import Pipeline]]. Back: [[3. Quest Texture Compression and Platform Overrides]]. Next: [[5. Worked Example and Import Pitfalls]].
> [!warning] Code not compiled in Unity
> Type-checked against Unity 6000.5.8f1 editor assemblies (see the hub). These processors have not been observed on a real import.
## 4.1 A texture rule
Convention used here (part 5 puts the folder tree in one place):
- Under `Assets/Art/`, textures get an Android ASTC override.
- Suffix `_N` or `_Normal` → Texture Type Normal Map, sRGB off, `ASTC_6x6`.
- Suffix `_UI` → `ASTC_4x4`, no mipmaps if you are slicing it as UI (optional; Sprites are a different Texture Type).
- Everything else colour-like → sRGB on, `ASTC_6x6`, max size 1024 unless the path contains `/Hero/` or another allow-list for 2048.
`Editor/QuestTexturePostprocessor.cs`:
```csharp
using UnityEditor;
using UnityEngine;
namespace AssetImportPipeline
{
public sealed class QuestTexturePostprocessor : AssetPostprocessor
{
// Bump when the rules change so Unity reimports existing art.
public override uint GetVersion() => 3;
void OnPreprocessTexture()
{
if (!ShouldProcess(assetPath)) return;
var ti = (TextureImporter)assetImporter;
bool isNormal = HasSuffix(assetPath, "_N") || HasSuffix(assetPath, "_Normal");
bool isUi = HasSuffix(assetPath, "_UI");
bool allow2048 = assetPath.Replace('\\', '/').Contains("/Hero/");
if (isNormal)
{
ti.textureType = TextureImporterType.NormalMap;
ti.sRGBTexture = false;
}
else if (isUi)
{
ti.textureType = TextureImporterType.Default;
ti.sRGBTexture = true;
ti.mipmapEnabled = false;
}
else
{
ti.textureType = TextureImporterType.Default;
ti.sRGBTexture = true;
ti.mipmapEnabled = true;
}
var android = ti.GetPlatformTextureSettings("Android");
android.overridden = true;
android.maxTextureSize = isUi ? 1024 : (allow2048 ? 2048 : 1024);
android.format = isUi ? TextureImporterFormat.ASTC_4x4 : TextureImporterFormat.ASTC_6x6;
ti.SetPlatformTextureSettings(android);
}
static bool ShouldProcess(string path)
{
var p = path.Replace('\\', '/');
return p.StartsWith("Assets/Art/") && !p.StartsWith("Assets/Art/_Defaults/");
}
static bool HasSuffix(string path, string suffix)
{
var name = System.IO.Path.GetFileNameWithoutExtension(path);
return name.EndsWith(suffix, System.StringComparison.OrdinalIgnoreCase);
}
}
}
```
`_Defaults` is excluded so the representative textures you built Presets from are not fighting the postprocessor while you edit them.
`textureType`, `sRGBTexture`, and `mipmapEnabled` are official `TextureImporter` properties (present in 6000.5.8f1). If a property you remember from an older script has been renamed, check the 6000.5 Scripting API rather than guessing — this listing only uses names that type-checked against that Editor.
## 4.2 A model rule
`Editor/ModelImportPostprocessor.cs`:
```csharp
using UnityEditor;
namespace AssetImportPipeline
{
public sealed class ModelImportPostprocessor : AssetPostprocessor
{
public override uint GetVersion() => 2;
void OnPreprocessModel()
{
var path = assetPath.Replace('\\', '/');
if (!path.StartsWith("Assets/Art/")) return;
var mi = (ModelImporter)assetImporter;
mi.globalScale = 1f;
mi.useFileScale = true;
mi.importBlendShapes = path.Contains("/Characters/");
mi.animationType = path.Contains("/Characters/")
? ModelImporterAnimationType.Generic
: ModelImporterAnimationType.None;
if (mi.animationType == ModelImporterAnimationType.None)
mi.importAnimation = false;
}
}
}
```
`globalScale`, `useFileScale`, `importBlendShapes`, `animationType`, and `importAnimation` are the official names used here and will be confirmed at compile time against 6000.5.8f1. If a DCC export is in centimeters and still comes in 100× large, the fix is usually in the DCC (export 1 unit = 1 meter) or a one-off `globalScale` of `0.01` on that file — do not silently scale every mesh in the postprocessor without a comment and a `GetVersion` bump, or you will hide a real export bug.
## 4.3 What not to do in a postprocessor
- **Do not move, rename, or delete assets** from `OnPostprocessAllAssets` as a matter of course. It is easy to loop (move → import → move) and it fights Git. If you need a tidy folder, do it as an explicit Editor menu.
- **Do not start a second import** of the same asset from inside its own preprocess.
- **Do not touch runtime scene objects.** Import runs in the Editor, including in batch mode ([[Build Automation and CI]]), often with no scene open.
- **Do not swallow exceptions.** A failed postprocessor can leave a half-configured importer; let it fail loud.
- **Do not forget `GetVersion`.** Shipping a "fix" at `GetVersion() => 1` still will leave already-imported art untouched.
If a Preset and a postprocessor both apply, the postprocessor wins on the next import of that file, because it runs as part of the import. Keep them consistent, or skip `_Defaults` as above and let folder rules own `Assets/Art/`.
Next: [[5. Worked Example and Import Pitfalls]].