This is a workaround for the infinite loop bug that is most commonly encountered when implementing configuration automation when importing new assets (such as automatically changing to compressed texture format for mobile) to increase pipeline efficiency for the entire project.

Main cause

`AssetPostprocessor` event handlers (e.g. `OnPostprocessTexture`) are hooked ``at the very moment'' Unity is about to complete the asset import process. During this process, if you explicitly call the command (`ImportAsset` or `WriteImportSettingsIfDirty`) that says ``Please update the database and import again because the settings have changed,'' Unity will start importing from the beginning again, completing a never-ending circle of processing (infinite loop).

Specific solutions

This is the correct way to write `AssetPostprocessor` that completely prevents recursive imports.

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

public class TextureAutoImporter : AssetPostprocessor
{
    // ➔ Use events to override settings before import (recommended)
    void OnPreprocessTexture()
    {
        TextureImporter textureImporter = (TextureImporter)assetImporter;
        
        // Check the current setting value and bypass the process if it is already the intended setting
        if (textureImporter.mipmapEnabled == false)
        {
            // Just rewrite the properties! (Never call SaveAssets or ImportAsset)
            textureImporter.mipmapEnabled = true;
            
            // *Unity internally detects "Dirty (changed)" and automatically saves the import settings only once.
        }
    }
}
#endif