Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


OnPreprocessAsset()

Add this function to a subclass to get a notification just before any Asset is imported.
Read time 1 minuteLast updated 7 days ago

Definition

public void OnPreprocessAsset()

Remarks

This lets you control the import settings through code. Unlike other `OnPreprocess` callbacks such as OnPreprocessTexture or OnPreprocessModel, `OnPreprocessAsset` does not automatically register a dependency on the postprocessor. This means that if your subclass only implements `OnPreprocessAsset`, changing the value returned by AssetPostprocessor.GetVersion does not trigger a reimport of affected assets. To register dependencies explicitly, use AssetImportContext.DependsOnCustomDependency or AssetImportContext.DependsOnArtifact through the AssetPostprocessor.context property. Note: If your subclass also implements another callback such as OnPreprocessTexture, the dependency is registered by that callback and AssetPostprocessor.GetVersion works as expected.

Examples

using UnityEditor;class PresetEnforcer : AssetPostprocessor{ void OnPreprocessAsset() { if (assetImporter.importSettingsMissing) { ModelImporter modelImporter = assetImporter as ModelImporter; if (modelImporter != null) { if (!assetPath.Contains("@")) modelImporter.importAnimation = false; modelImporter.materialImportMode = ModelImporterMaterialImportMode.None; } } }}