Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Canceling an Asset import in an AssetPostProcessor

Discussion in 'Editor & General Support' started by llde_chris, Jan 7, 2010.

  1. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    Hi,

    Is there a way to tell in OnPreprocessTexture() for example that after analyzing the assetPath/filename that you do *not* want Unity to continue with the import process?
     
  2. Joe-Robins

    Joe-Robins

    Unity Technologies

    Joined:
    Apr 21, 2008
    Posts:
    430
  3. ArtemGPlaytika

    ArtemGPlaytika

    Joined:
    Jan 12, 2021
    Posts:
    2
    But I tried this hack and it works:

    public class WrongNamePostprocessor : AssetPostprocessor
    {
    private bool _isWrong = false;
    // Before the texture is imported
    public void OnPreprocessTexture()
    {
    if (assetPath.Contains("_wrong"))
    {
    _isWrong = true;
    LogError("I don't need that wrong file");
    }
    }

    // After the texture is imported
    public void OnPostprocessTexture(Texture2D texture)
    {
    if (_isWrong)
    {
    AssetDatabase.DeleteAsset(assetPath);
    }
    }
    }


    It will be imported and immediately deleted
     
    lvantilburg likes this.